
class R { private int x; private int y;
void getdata(int x1,int x2)
{
x=x1;
y=y1;
}
void displaydata()
{
system.out.println(x+"\t"+y);
}
}
class J { public static void main(String args[]) { R c1,c2; c1 = new R(); c2 = new R();
c1.getdata(10,20);
c2.getdata(30,40);
c1.displaydata();
c2.displaydata();
System.out.println(c1.x+"\t"+c1.y);
System.out.println(c2.x+"\t"+c2.y);
}
}
//THE PROGRAM IS SHOWING 6 ERRORS 1.PACKAGE SYSTEM DOES NOT EXIT 2.X HAS PRIVATE ACCESS IN R 3.Y HAS PRIVATE ACCESS IN R

Java Program
Private modifier does not allow to access the private variable, method of another class.
class R {
int x;
int y;
void getdata(int x1,int y1)
{
x=x1;
y=y1;
}
void displaydata()
{
System.out.println(x+"\t"+y);
}
}
class J {
public static void main(String args[]) {
R c1,c2;
c1 = new R();
c2 = new R();
c1.getdata(10,20);
c2.getdata(30,40);
c1.displaydata();
c2.displaydata();
System.out.println(c1.x+"\t"+c1.y);
System.out.println(c2.x+"\t"+c2.y);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.