File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "get method" Watch "get method" New topic

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);
Sandys(int ballcount){
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

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,
Thomas Kijftenbelt
Ranch Hand

Joined: Feb 13, 2002
Posts: 73
Normally get and set methods are used to access private (encapsulated) variables from another class.
I agree. Here's the link:
subject: get method
It's not a secret anymore!