aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes mock problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "mock problem" Watch "mock problem" New topic
Author

mock problem

jone wiilum
Ranch Hand

Joined: Mar 24, 2007
Posts: 49
public class Honley{
public static int i =99;
public static void main(String argv[]){
Honley h = new Honley();
h.wine();
}
public void wine(){
i = 10;
int i = 20;
System.out.println(this.i);

}
}

out put is 10 how?
[ August 24, 2007: Message edited by: jone wiilum ]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by jone wiilum:
...out put is 20 how?

Output is 10.


"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
jone wiilum
Ranch Hand

Joined: Mar 24, 2007
Posts: 49
yes output is 10 but how it come
we have int i=20; in method
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by jone wiilum:
yes output is 10 but how it come
we have int i=20; in method

In the body of the method, a new variable "i" is declared. The new "i" is local to the method, and it's different than the static "i" that is declared in the class. When we say "this.i" we are getting the static "i" of this instance -- not the local "i".

[ August 24, 2007: Message edited by: marc weber ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mock problem