Hints
They are three purpose to use super keyword.
1. To call super class constructors from sub class constructors.
super();
super(10,20);
2. To access super class member variables. This is not accessible by sub class If sub class has the same variable name otherwise super.
super.variable_name = 10;
3. To call super class methods. This is not accessible by sub class If sub class has the same method name which is in super class.
super.display();
|
class Cricket {
int runs;
int over;
public Cricket(){
over = 99;
}
public void display(){
System.out.println("Runs: "+runs+";Over: "+over);
}
}
class CricketCounter extends Cricket{
public CricketCounter(){
super();
}
public void display(){
super.runs = 82;
super.display();
}
}
class Solution {
public static void main(String args[])throws Exception{
CricketCounter cric = new CricketCounter();
cric.display();
}
}
|