Stronger and weaker class – JAVA

In case of method overriding the access privilege of the method in the derived class should always be equal or greater than the access privilege of the method in super class.

 

public           >             protected          >          private

strongest                                                          weakest

 

program:

//PROGRAM TO SHOW CONCEPT OF STRONGER AND WEAKER CLASS PREVILEGE

class Base

{

public void show1()

{

}

private void show2()

{

}

protected void show3()

{

}

}

 

class Derived extends Base

{

/*private void show1()     error- attempting to assign weaker access previlege

{

}*/

protected void show2()

{

}

public void show3()

{

}

public static void main(String a[])

{

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *