| Author |
reference id
|
abhinav sood
Greenhorn
Joined: Aug 05, 2011
Posts: 9
|
|
this program gives the output null and zero can any one explain that.....
[moderator edit: added code tags]
|
 |
Jan Cumps
Bartender
Joined: Dec 20, 2006
Posts: 2207
|
|
Welcome to the Ranch, Abhinav !
can any one explain that.....
yes:
First you call:
This will create a new emp() object, call its get() member, and then loses the reference to the object (you don't store the object in a variable).
Then you call:
This will create a brand new object, call its show() method -- that will print null and 0 because you didn't use get() to set its members, and then loses the reference to the object too.
What should you have done:
when creating the object, store it in a variable of type emp (emp myEmp = new ....)
then call the members of that variable (myEmp.get(), myEmp.show() )
Some style remarks:
A class by convention starts with upper case (class Emp)
A method to set properties should be called set..(), not get..().
|
 |
 |
|
|
subject: reference id
|
|
|