Read the following topic, then explain briefly what did you understand from it?
ID: 3723647 • Letter: R
Question
Read the following topic, then explain briefly what did you understand from it?
Constructor:
Example:
public class BankAccount {
private double balance;
public BankAccount()
{ balance = 0; }
public BankAccount(double initialBalance)
{
balance = initialBalance;
System.out.print("Balance is: ");
System.out.println(balance + 10);
}
}
1- Is public BankAccount() considered as a constructor? Why?
Answer:
Yes, It has the name of the class.
2- What is the output of:
public static void main(String[] args){
new BankAccount(10.5);
}
Answer:
Balance is: 20.5
Explanation / Answer
It can be inferred from the above topic that-
Like in the given example,
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.