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 the difference between runnable and callable interface in java?
Can Exception handling we can handle multiple catch blocks?
What is * argv?
What is the range of a character variable?
Do you know why doesn't the java library use a randomized version of quicksort?
What are static methods?
What is local class in java?
what do you mean by java annotations?
What is treemap in java?
List the three steps for creating an object for a class?
Explain the significance of class loaders in bootstrap?
What type of variable is gender?
What is final variable?
What is meant by local variable and instance variable?
What is treeset in java collection?