Differentiate constructor and a method and how are it be
used?
Answer Posted / vishwanath
mainly there are
i.constructor name is same as the class name whereas method name doesn't.
ii.constructor is implicitly called when an object is created.....but the method is explicitly called by using object.
iii.constructor has no return type hence it doesn't return anything.....but method has return type.
iv.constructor is used to create and initialize data members.....where as method is created to code the specific task.
| Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
Can extern variables be initialized?
What is a list in java?
Explain importance of finally block in java?
Explain the importance of finally block in java?
How to check if linked list contains loop in java?
What is the purpose of file class?
how we can make a read-only class in java?
What is listnode in java?
What are dot operator queries?
What is "this" keyword in java? Explain
What is logical variable?
In multi-threading how can we ensure that a resource isn't used by multiple threads simultaneously?
Can we declare the main method of our class as private?
Why vector is used in java?
What is passing value java?