need help with these java questions .1)Customer [ ] clients; How many objects we
ID: 3811225 • Letter: N
Question
need help with these java questions
.1)Customer [ ] clients;
How many objects were created when executing the above line of code?
2) clients = new Customer[25];
How many objects were created when executing the above line of code?
3) What is the result of executing the following line of code:
System.out.println(clients[[3].getBalance()); // the Customer class has a getBalance() method
4) Write the code to create the 25 Customer objects using the default constructor and assign each slot in the array the address of a Customer object,
5) Write the code to print the balance of the 5th Customer.
Explanation / Answer
1)Customer [ ] clients;
Answer: 0
0 objects were created when executing the above line of code
2) clients = new Customer[25];
Answer: 25
25 objects were created when executing the above line of code
3) What is the result of executing the following line of code:
System.out.println(clients[[3].getBalance()); // the Customer class has a getBalance() method
Answer: NullPointerException
Becuase we have declared the objects but not instantiated with new operator.
4) Write the code to create the 25 Customer objects using the default constructor and assign each slot in the array the address of a Customer object,
Answer:
for(int i=0; i<clients.length; i++) {
clients[i] =new Customer();
}
5) Write the code to print the balance of the 5th Customer.
Answer: System.out.println(clients[[4].getBalance());
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.