answersLogoWhite

0

Can you define class as private in java?

Updated: 8/20/2019
User Avatar

Wiki User

11y ago

Best Answer

Yes. However, ONLY nested classes (as in sub-classes of a top-level class) could be declared as private. The main (top-level) class cannot be private as it couldn't be accessed.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you define class as private in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you uss static in java?

It is uss to define class and method of pogrom's.


What is function in java terminology?

In Java, a function is called a "method". In Java as well as other languages, a method is a function defined specifically for one class. In Java, this is the only way to define functions, therefore, all functions are methods.In Java, a function is called a "method". In Java as well as other languages, a method is a function defined specifically for one class. In Java, this is the only way to define functions, therefore, all functions are methods.In Java, a function is called a "method". In Java as well as other languages, a method is a function defined specifically for one class. In Java, this is the only way to define functions, therefore, all functions are methods.In Java, a function is called a "method". In Java as well as other languages, a method is a function defined specifically for one class. In Java, this is the only way to define functions, therefore, all functions are methods.


What are the things not inherited from parent class in Java?

Private members are not inherited from the parent class.


Does java class must have public method?

no you can have a class with no public methods and even with a a private constructor public class Example { //constructor private Example(){ } }


When you go for private constructor in java?

When you do not want any other class to be able to instantiate your current class


How can i add an employee class and an account class to the console application projects?

You create a new file for each class, and define a class in each. In Java, you use the "class" keywoard.


Can you declared constructor as private?

If you declare the main method anything other than public, it will not run. If you declare main method as private, you would not be able to execute the class as a standalone java program. Any java class that needs to be executed as a standalone file needs to have a main method that is public, static and returns a void. Otherwise the Java compiler would not recognize the file as an executable standalone java file and would not allow you to run it.


Define socket in java?

The Socket class in Java is an endpoint in a standard TCP connection. The Socket class implements methods which take care of all the overhead required with TCP communication.


Can you define variables in interface in java?

yes we can define a variable in an interface in java.


Can you define the constructor as private?

Yes, you can. Making a constructor private ensures that no other class can instantiate that class you just created with a private constructor. It is usually used in Singleton Patterns.


What does it mean in java when a constructor is undefined?

When a constructor is not define in java then the instance used in class is not optimised the value and therefore some times it generates some garbage value. By the way , When we not define a constructor then generally it not distrub the execution of the program.


Are the private access specifiers in Java and C plus plus the same?

No.In Java, the private access modifier restricts member access to the class in which the member is declared. But in C++, private members are also accessible to friends of the class in which they are declared. The rough equivalent in Java would be package private access.Not that Java doesn't have access specifiers, it has access modifiers. When no modifier is specified, default access is implied, which is package private for classes and public for interfaces.