save as class1.java
/*accessing 1 class member into another class member*/
class class1
{
int a=100,b=100;
void fun1()
{
System.out.println("i am class1 and in fun1()");
}
void fun2()
{
System.out.println("i am class1 and in fun2()");
}
public static void main(String args[])
{
/*class1 class1 = new class1();
System.out.println("a :"+class1.a);
System.out.println("b :"+class1.b);
class1.fun1();
class1.fun2();*/
}
}
================================================
save as class2.java
/*accessing 1 class member into another class member*/
class class2
{
int a=200,b=200;
void fun1()
{
System.out.println("i am class2 and in fun1()");
}
void fun2()
{
System.out.println("i am class2 and in fun2()");
}
public static void main(String args[])
{
/*class2 class2 = new class2();
System.out.println("a :"+class2.a);
System.out.println("b :"+class2.b);
class2.fun1();
class2.fun2();*/
}
}
============================================
save as class3.java
/*accessing 1 class member into another class member*/
class class3
{
int a=300,b=300;
void fun1()
{
System.out.println("i am in class3 and fun1()");
}
void fun2()
{
System.out.println("i am in class3 and fun2()");
}
public static void main(String args[])
{
class1 class1 = new class1();
class2 class2 = new class2();
class3 class3 = new class3();
System.out.println("\na in class 1 :"+class1.a);
System.out.println("b in class 1 :"+class1.b);
class1.fun1();
class1.fun2();
System.out.println("\na in class 2 :"+class2.a);
System.out.println("b in class 2 :"+class2.b);
class2.fun1();
class2.fun2();
System.out.println("\na in class 3 :"+class3.a);
System.out.println("b in class 3 :"+class3.b);
class3.fun1();
class3.fun2();
}
}
====================================================
run :
class3.java
==================================================
output :
i am in class1 and fun1()
i am in class1 and fun2()
a in class 1 :300
b in class 1 :300
i am in class3 and fun1()
i am in class3 and fun2()
a in class 2 :300
b in class 2 :300
i am in class3 and fun1()
i am in class3 and fun2()
a in class 3 :300
b in class 3 :300
/*accessing 1 class member into another class member*/
class class1
{
int a=100,b=100;
void fun1()
{
System.out.println("i am class1 and in fun1()");
}
void fun2()
{
System.out.println("i am class1 and in fun2()");
}
public static void main(String args[])
{
/*class1 class1 = new class1();
System.out.println("a :"+class1.a);
System.out.println("b :"+class1.b);
class1.fun1();
class1.fun2();*/
}
}
================================================
save as class2.java
/*accessing 1 class member into another class member*/
class class2
{
int a=200,b=200;
void fun1()
{
System.out.println("i am class2 and in fun1()");
}
void fun2()
{
System.out.println("i am class2 and in fun2()");
}
public static void main(String args[])
{
/*class2 class2 = new class2();
System.out.println("a :"+class2.a);
System.out.println("b :"+class2.b);
class2.fun1();
class2.fun2();*/
}
}
============================================
save as class3.java
/*accessing 1 class member into another class member*/
class class3
{
int a=300,b=300;
void fun1()
{
System.out.println("i am in class3 and fun1()");
}
void fun2()
{
System.out.println("i am in class3 and fun2()");
}
public static void main(String args[])
{
class1 class1 = new class1();
class2 class2 = new class2();
class3 class3 = new class3();
System.out.println("\na in class 1 :"+class1.a);
System.out.println("b in class 1 :"+class1.b);
class1.fun1();
class1.fun2();
System.out.println("\na in class 2 :"+class2.a);
System.out.println("b in class 2 :"+class2.b);
class2.fun1();
class2.fun2();
System.out.println("\na in class 3 :"+class3.a);
System.out.println("b in class 3 :"+class3.b);
class3.fun1();
class3.fun2();
}
}
====================================================
run :
class3.java
==================================================
output :
i am in class1 and fun1()
i am in class1 and fun2()
a in class 1 :300
b in class 1 :300
i am in class3 and fun1()
i am in class3 and fun2()
a in class 2 :300
b in class 2 :300
i am in class3 and fun1()
i am in class3 and fun2()
a in class 3 :300
b in class 3 :300