class Data {
// private variable
private String name;
}
public class Main {
public static void main(String[] main){
// create an object of Data
Data d = new Data();
// access private variable and field from another class
d.name = "Programiz";
}
}
// Java program to illustrate
protected modifier
package one;
// Class A
public class A
{
protected void display()
{
System.out.println("Welcome to softhunt.net");
}
}
// Java program to illustrate
protected modifier
package two;
import one.*; // importing all classes in package one
// Class B is subclass of A
class B extends A
{
public static void main(String args[])
{
B obj = new B();
obj.display();
}
}
// Java program to illustrate
public modifier
package one;
public class A
{
public void display()
{
System.out.println("Welcome to softhunt.net");
}
}