• Post Reply Bookmark Topic Watch Topic
  • New Topic

Default for Class is Public?  RSS feed

 
AhFai Chan
Ranch Hand
Posts: 81
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a package with several different class files e.g. Name, AddressList, PhoneList, EmailList etc, this is how I break down the business logic into manageable Java objects and so far it is working out for me.

When I reviewed the code, I observed that I've left the default Eclipse class type as e.g. class AddressList {} or class PhoneList {} etc

These classes are accessible to all the other classes and to the final layout in the same package without "extends". Java seems to default to "public".

Is this the normal behavior?



 
Scott Shipp
Ranch Hand
Posts: 223
12
Eclipse IDE IntelliJ IDE Java Scala Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's normal. The default Java behavior is called package-private. More info here. http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AhFai Chan wrote: the default Eclipse class type as e.g. class AddressList {}

"Eclipse" class type? There's no such thing. Java is Java regardless of what editor you use.

These classes are accessible to all the other classes and to the final layout in the same package without "extends". Java seems to default to "public".

As pointed out, no. Try to access those classes from another package and you'll see how non-public they are.

 
AhFai Chan
Ranch Hand
Posts: 81
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scott Shipp wrote:That's normal. The default Java behavior is called package-private. More info here. http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html


Gotcha, thanks for the link.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!