aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes get method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "get method" Watch "get method" New topic
Author

get method

weiliu lili
Ranch Hand

Joined: Apr 11, 2002
Posts: 46
public class Sandys{
private int court;
public static void main(String argv[]){
Sandys s = new Sandys(99);
System.out.println(s.court);
}
Sandys(int ballcount){
court=ballcount;
}
}
</b>
The result:Compilation and run with an output of 99
i thought private instance variable should be matched with a get method
,in this case getCourt{},so when should i define a get method in a class?
Asif Mahmood
Greenhorn

Joined: Jun 11, 2001
Posts: 29
Out must be 99...
court is an instance variable and is automatically initialized with 0. In the constructor of Sandys, court is initialized with 99. and no getCourt method is required.
Best regards,
-Asif
Thomas Kijftenbelt
Ranch Hand

Joined: Feb 13, 2002
Posts: 73
Hi,
Normally get and set methods are used to access private (encapsulated) variables from another class.
Greetings,
TK
SCJP
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get method