answersLogoWhite

0

What does private mean in java?

User Avatar

Anonymous

14y ago
Updated: 8/16/2019

Members marked private can't be accessed by code in any class other than the class in which the private member was declared. Let's make a small change to the Parent class from an earlier example.

package pack1;

public class Parent {

private String getName() {

return "Parent";

}

}

Now the getName() method is private and is not visible from within the Child class and the same piece of code would throw up the below compilation error when you try to compile the class.

cannot find symbol

symbol : method getName()

This error method looks as if the method getName() does not exist at all. Of course the method exists but unfortunately it is declared private and hence no class (except the class that has the exact code written into it) can access it. This includes a child class that extends the parent class that has the method.

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

Why java is secured compare with other language?

Because there is an access specifier called private in java by which security can be provided


What is subroutine in java?

Subroutine mean what (in java)?


What does Systemout mean in java?

System.out refers to the Java console.


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.


What do you mean by multithread program in java?

A Program in Java that spawns multiple threads is called a multithreaded program in Java.


What does the word java mean?

Java is an island in Indonesia, but in slang it means coffee.


What is acess spacifier in java?

An Access Modifier is a key word in java that determines what level of access or visibility a particular java variable/method or class has. There are 4 basic access modifiers in java. They are: 1. Public 2. Protected 3. Default and 4. Private Private is the most restrictive access modifier whereas public is the least restrictive. Default is the access protection you get when you do not specifically mention an access modifier to be used for a java object.


What does the term Java logging mean?

Java logging is data logging for the Java platform. Logging is a term in software for recording activity. Therefore Java logging is recording activity for Java.


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

Private members are not inherited from the parent class.


What does private int mean in java?

The private keyword denotes that the field or method is hidden from view of any other class. class MyClass { private int n; // n cannot be accessed by any class except MyClass private void doSomething(){} // doSomething cannot be accessed by any class except MyClass }


Explain different access modifier in java?

An Access Modifier is a key word in java that determines what level of access or visibility a particular java variable/method or class has. There are 4 basic access modifiers in java. They are: 1. Public 2. Protected 3. Default and 4. Private Private is the most restrictive access modifier whereas public is the least restrictive. Default is the access protection you get when you do not specifically mention an access modifier to be used for a java object.


Does java script coding mean using it for Java programs only?

Java script coding is computer coding, many things require Java, and you need to have Java enabled to view these types of programs.