Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

what is the default instace variable  RSS feed

 
joethe moron
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you dont put public or private in front?

class imanidiot{
int intvar;
}

is intvar public or private by default?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, welcome to the ranch!

The default visibilitiy is cleverly enough called "default visibility." Sometimes package visibility or package private.HERE is a page with a good discussion near the end.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"joethe moron,"

Welcome to JavaRanch!

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names.

You can edit your display name here.

Thank you for your prompt attention, and enjoy the ranch!

-Marc
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Dude.

If you don't specify an access modifier, it defaults to 'default'

Default access is package access. The class is visible to any class inside the same folder/package, but to nothign outside of the folder.

So, leaving out an access modifier does not default it to public, private or protected. It defaults it to default, or package.
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kameron McKenzie:
Hey Dude.

If you don't specify an access modifier, it defaults to 'default'

Default access is package access. The class is visible to any class inside the same folder/package, but to nothign outside of the folder.

So, leaving out an access modifier does not default it to public, private or protected. It defaults it to default, or package.


I would stick to using "package" instead of "folder" as the two are not always analogous.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!