Unit 2 Inheritence
Unit 2 Inheritence
SNIPPET
SNIPPET
Public:
Members with the public access modifier are
accessible from anywhere, both within the class
hierarchy and from outside the class.
Public members of a superclass are inherited
and can be accessed in the subclass.
Protected:
Members with the protected access modifier are
accessible within the same package and by
subclasses, even if they are in a different package.
Protected members of a superclass are inherited
by the subclass.
default:
If no access modifier is specified (default
access), members are accessible within the same
package but not outside of it.
Default members of a superclass are inherited by
the subclass if they are in the same package.
private:
Members with the private access modifier are only
accessible within the class where they are
declared.
Private members of a superclass are not
inherited by the subclass
public Employee() {
this(0); // Calls the parameterized constructor with an initial value of 0
}
public Employee(int value) {
this.value = value;
}
}
}
public void m1()
{
super();
interface InterfaceDemo
{
void m1(); abstract interface InterfaceDemo
void m2(); {
void m3(); public abstract void m1();
} public abstract void m2();
public abstract void m3();
}
}
@Override
public void method2() {
System.out.println("InterfaceDemo2- method2() implementation");
}
@Override
public void method3() {
System.out.println("InterfaceDemo3- method3() implementation");
}
@Override
public void method4() {
System.out.println("InterfaceDemo4- method4() implementation");
}
}