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 an immutable class?
Explain the difference between private, public, package and protected in java?
Write a method to check if input string is palindrome?
What does a method signature consist of?
What are the advantages of autoboxing?
Explain about the interpreter in java?
How do you represent a space in regex java?
What is a method vs function?
What is math in java?
What is an escape character in java?
What is serialization in java?
What is the flag in java?
What is the platform?
Explain java coding standards for interfaces?
What is namespace in java?