Answer Posted / dinesh
All the objects that are created must be given initial
values.There are two approach for this.
1)Using the dot operator to access the instance variables
and then assign values to them individually---This is a
tedious approach.
2)Use of getData method to initialize each object
individually.eg:add.getData(10,15)
To make this simpler Java supports a special type of method
called a Constructor,that enables an object to initialize
itself when it is created.Constructor have the same name as
the class itself and they do not specify a return type,not
even void,bcoz they return the instance of the class itself.
| Is This Answer Correct ? | 23 Yes | 4 No |
Post New Answer View All Answers
Explain about collection interface in java?
How many tetrahedral voids are there in bcc?
Is 0 true or false in java?
Why pointers are not used in java?
What differences exist between iterator and listiterator?
Can we make constructors static?
What do you mean by formatting?
What are the three parts of a lambda expression? What is the type of lambda expression?
What is an 8 bit word?
What is the difference between checked exception and unchecked exception?
What is meant by design patterns?
What is the difference between an interface and an abstract class?
What are drawbacks of singleton class?
What is the use of singleton?
What is a java list?