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
Can an integer be a string?
Can memory leak happen java?
What must a class do to implement an interface in java programming?
What is string variable?
How many return statement are allowed in a function?
What is string in java? String is a data type?
Which class cannot be a subclass in java?
What are the 7 types of characters?
What is anagram number?
What is java jit compilers?
Can I learn java without any programming experience?
What is the symbol for space?
What is a website container?
Why we use set in java?
What is the final field modifier?