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
What is connection class in java?
What carriage return means?
Can constructor be protected in java?
What is primitive data type in java?
Is void a data type in java?
what is abstract class in Java?
Compare Mutex and Semaphore in java.
What is the history of java?
How do you stop a thread in java?
Is there a way to increase the size of an array after its declaration?
What is static import in java?
When should a function throw an exception?
What is nextline method in java?
What is multi-catch block in java?
Can a static class have a constructor?