i have a simple class Gertude in which i have a private variable number of type int.
I access this variable by getter and setter methods.
initially i set the value of this number to 100 by saying gerry.setNumber(100);and print it back by System.out.println(gerry.getNumber()) where gerry is a Gerude object.
Everything runs fine till here
But When I try printing the value of this gertude variable by saying (new Gertude()).getNumber() it always comes to 0
I cant understand as to why this mismatch is happening
what is your question?. Both the objects are different.Your second SOP will print '0' always as the instance variable of type int is initialized default to 0.
Be Objectively Oriented.Explore the power of OOPs.
My Blog, Eclipse EMF Query committer.
Originally posted by Rajat Bhatnagar: ... But When I try printing the value of this gertude variable by saying (new Gertude()).getNumber() it always comes to 0...
You're creating a new instance of Gertude, and then calling getNumber() before setting the number to anything, so number has its default of 0.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org