Login    Forum    Search    FAQ   Blog

Board index » Server Side Development » Java




 Page 1 of 1 [ 5 posts ] 



Author Message
 Post subject: Why Public?
 Post Posted: Fri Nov 27, 2009 8:11 pm 
Offline

Joined: Sat Feb 21, 2009 2:29 pm
Posts: 67
Why do I need to declare something public outside a method?
Code:
public class Math{
          public int x =2;
}



why not just:

public class Math{
           int x =2;
}


Top 
 Post subject: Re: Why Public?
 Post Posted: Fri Nov 27, 2009 8:11 pm 
Offline

Joined: Sat Feb 21, 2009 11:06 am
Posts: 1794
Try it and see.


Top 
 Post subject: Re: Why Public?
 Post Posted: Fri Nov 27, 2009 8:11 pm 
Offline

Joined: Sat Feb 21, 2009 1:08 pm
Posts: 549
Nothing says that you need to declare it as public (and you seldom declare attributes as public)


Top 
 Post subject: Re: Why Public?
 Post Posted: Fri Nov 27, 2009 8:12 pm 
Offline

Joined: Sat Feb 21, 2009 11:06 am
Posts: 1794
Who says that?

If a member in class C is not declared private, protected, or public, it has package access, or default access.


Top 
 Post subject: Re: Why Public?
 Post Posted: Fri Nov 27, 2009 8:12 pm 
Offline

Joined: Sat Feb 21, 2009 2:29 pm
Posts: 67
I think I get it now.
Thanks for the answers : )


Top 
Display posts from previous:  Sort by  
 
 Page 1 of 1 [ 5 posts ] 




Board index » Server Side Development » Java


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron