Public Class A (Protected Int N Public A (N 0 ) Public A (Int I) (N I ) Public Void Setn (Int I) (N I ) Public Int Getn (Return N ) )
Public Class A (Protected Int N Public A (N 0 ) Public A (Int I) (N I ) Public Void Setn (Int I) (N I ) Public Int Getn (Return N ) )
Rule:
Have to use the `extends’ keyword after the subclass name and before the
superclass name.
public class A {
protected int n;
public A(){
n=0;
n=i;
n=i;
return n;
}
public class B extends A {
public double d;
d=d1;
return d;
return n;
A a=new A(10);
B b=new B();
a.setN(200);
b.setN(400);
//System.out.println("b.n: "+b.getN());
b.setD(15.7);
System.out.println("b.D: "+b.getD());
}
# Super has two different forms . the first calls the superclass ‘constractor’. The
second is used to access a member of the superclass that has been hidden by a
member of a sub class.
# method overriding
When a method in a subclass has the same name and type signature as a method
in its super class , then the method in the subclass is said to override the method
in the superclass.
Rule:
public class A {
int i,j;
i=a;
j=b;
void show(){
}
}
int k;
super(a,b);
k=c;
void show(){
System.out.println("k: "+k);
A a=new A(4,5);
a.show();
B b=new B(1,2,3);
b.show();
# Abstract :
void callmetoo(){
void callme(){
B b=new B();
b.callme();
b.callmetoo();
}
}
# Final:
int a;
final a=10;
To disallow a method from being overridden final have to be used as modifier at the start of its
declaration. Method declared as final cannot be overridden.
class A{
class B extends A {
ILLIGAL!
//…..
//…..