aspose file tools*
The moose likes Beginning Java and the fly likes default class visibility Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "default class visibility" Watch "default class visibility" New topic
Author

default class visibility

Desmond
Greenhorn

Joined: Nov 25, 2001
Posts: 1
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

Joined: May 25, 2001
Posts: 388
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

Joined: Jul 22, 2000
Posts: 9046
    
  10
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.

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Sadaf Zaidi
Greenhorn

Joined: Oct 09, 2001
Posts: 29
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: default class visibility