Write a Java Program to implement multilevel inheritance by Applying
various access controls to its data members and methods
class A
{
int a;
void set_a(int i)
{
a=i;
}
void show_a()
{
System.out.println("The valueof a is:"+a);
}
}
class B extends A
{
int b;
void set_b(int i)
{
b=i;
}
void show_b()
{
System.out.println("The valur of b is:"+b);
}
}
class C extends B
{
int c;
void set_c(int i)
{
c=i;
}
void show_c()
{
System.out.println("The valur of c is:"+c);
}
void mul()
{
int ans;
ans=a*b*c;
System.out.println("The ans is:"+ans);
}
}
class Mlt
{
public static void main(String args[])
{
A obj_A=new A();
B obj_B=new B();
C obj_C=new C();
obj_C.set_a(2);
obj_C.set_b(3);
obj_C.set_c(4);
obj_C.show_a();
obj_C.show_b();
obj_C.show_c();
obj_C.mul();
}
}
{
int a;
void set_a(int i)
{
a=i;
}
void show_a()
{
System.out.println("The valueof a is:"+a);
}
}
class B extends A
{
int b;
void set_b(int i)
{
b=i;
}
void show_b()
{
System.out.println("The valur of b is:"+b);
}
}
class C extends B
{
int c;
void set_c(int i)
{
c=i;
}
void show_c()
{
System.out.println("The valur of c is:"+c);
}
void mul()
{
int ans;
ans=a*b*c;
System.out.println("The ans is:"+ans);
}
}
class Mlt
{
public static void main(String args[])
{
A obj_A=new A();
B obj_B=new B();
C obj_C=new C();
obj_C.set_a(2);
obj_C.set_b(3);
obj_C.set_c(4);
obj_C.show_a();
obj_C.show_b();
obj_C.show_c();
obj_C.mul();
}
}
..........................................OUTPUT...................................................
C:\jdk1.2\bin>javac Mlt.java
C:\jdk1.2\bin>java Mlt
The valueof a is:2
The valur of b is:3
The valur of c is:4
The ans is:24
..................................................................................................................
No comments:
Post a Comment