This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

get method

 
weiliu lili
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic