• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

default class visibility

 
Desmond
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering,... if you do not have explicity put the visibility of a class when defining the class, what is the default.
So, say for instance i have the following:
import java.util.*;
public class ManagerTest {
public static void main( String[] args)
{
...
}
}
class Employee
{
public Employee( String n, double s) {
...
}
}
class Manager extends Employee
{
public Manager( String n, doubles, int year, int month, int day) {
...
}
}

what would be the visibility of the Employee and Manager class in the enitre class file. I know that you can only have one public class in you're class file and that that public class should be the name of the file. So in this case,... the public class is ManagerTest so the file name would be ManagerTest.java.
Thus, the Employee and Manager class are not public. So does that make them private or protected?
Thanks for your help
Regards
Desmond Lee
 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
they are package visibility. if you do not put any access modifier then java defaults to package.
this is a rough list of visibilitys.
private: only within class
protected: private and subclasses
package: private, protected and classes within same package
public: everyone
karl
 
Marilyn de Queiroz
Sheriff
Posts: 9062
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Desmond,
Please read http://www.javaranch.com/name.jsp and re-register. We would like you to continue to be able to post here at JavaRanch.
 
Sadaf Zaidi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are package visibility. if you do not put any access modifier then java defaults to package.
private: Vlaid only in the class it is defined in.
public:Valid in all the classes in all packages.
protected:Valid in al, the classes of it's own package and valid in the outside classes(outside its package) which extends its class.
default:Valid only in all the classes of its own package.
Hope it helps
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic