/* */ Click to Join Live Class with Shankar sir Call 9798158723

What is private Members ?


By default all the members of a class would be private,The private data members cannot be accessed from outside the class. They can only be accessed by class or friend functions. All the class members are private by default.When preceding a list of class members, the private keyword specifies that those members are accessible only from member functions and friends of the class. This applies to all members declared up to the next access specifier or the end of the class.A function declared inside the private access specifier of the class, is known as a private member function.

Q.) Example of Private Members Function in Java .
	// Java program to illustrate error while
// using class from different package with
// private modifier
package p1;

class A
{
private void display()
	{
		System.out.println("shineskill");
	}
}

class B
{
public static void main(String args[])
	{
		A obj = new A();
		// Trying to access private method
		// of another class
		obj.display();
	}
}

Output
error: display() has private access in A
obj.display();