Java Program to explain Method Modifier using Extend Class & Abstract Class
Programabstract class A
{
int a;
public abstract void show();
}
class B extends A
{
int b,c;
B(int i,int j,int k)
{
a=i;
b=j;
c=k;
}
public void show()
{
System.out.println("a="+a);
System.out.println("b="+b);
System.out.println("c="+c);
}
final void disp()
{
System.out.println("Inside B Class Final Method");
}
}
class C extends B
{
static int i=10;
C(int i,int j,int k)
{
super(i,j,k);
}
public static void prt()
{
i=i*100;
System.out.println("Static Method:"+i);
}
private void display()
{
System.out.println("Private Method");
}
protected void msg()
{
System.out.println("Proctected Method");
}
/* void disp()
{
System.out.println("Final");
} Not Possible bcoz it is declared as final in the base class*/
}
class Methodmodi
{
public static void main(String args[])
{
B b = new B(10,20,30);
C c= new C(10,20,30);
c.show();
C.prt();
//c.display();Not possible bcoz it is private
c.msg();
c.disp();
}
}
No comments:
Post a Comment