Hello. I bolded the answers that I think are correct but I need confirmation so
ID: 3793715 • Letter: H
Question
Hello. I bolded the answers that I think are correct but I need confirmation so I can get a good grade. Thanks!
1.Write the header for the default constructor of a class called House.
public static House()
public int House()
public House(int numRooms, int floors)
public House()
public void House()
2. Which of the following is not true about a constructor?
It must have a void or return type.
It must have the same name as the class.
It should be declared public.
It initializes the instance variables of the class.
It must not have a void or return type.
Explanation / Answer
Note:You are right but am just giving clear reasons why those are correct to make you more clearly understood.
_________________
1)Ans)public House()
Reason:default constructor means a constructor have no arguments is called zero argumented constructor or default constructor.
To write a default constructor to a class we have to follow some rules.
1.The Constructor name must be exactly same as the class name(Case sensitive)
2.We should write any return type to the cosntructor even void also.There must be no return type.
3.No parameters for the default constructor.
By following all these rules the answer here is public House()
_________________
2)ans)It must have a void or return type.
Reason: I Already mentioned the rules to be followed write writing default constructor.In addition The purpose of the constructor is that to initialize the instance variables.
So in that way
It must have the same name as the class.
It should be declared public.
It initializes the instance variables of the class.
It must not have a void or return type.
These are all correct.But here the wrong statement is It must have a void or return type.
________________Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.