I've overridden a method and tried to access the overridden method but,the compiler says like"non-static variable super can not be referenced from a static content".
I tried calling the overridden method in the constructor of the sub class, well it worked fine but, i wanna access it outside of the constructor.
class vehicle{
static String name;
static int model;
static int price;
static String station;
public vehicle(){
model=220;
name="Ducati";
price=500000;
station="London";
}
public static void display(){
System.out.println("Name of the vehicle: "+name+"\nmodel: "+model+"\nprice: ```"+price+"\nservice station: "+station);
}
}
class bike extends vehicle{
static double rate;
public bike(){
rate=0.25;
}
public static void display(){
System.out.println("Vehicle name: "+name+"\nmodel number: "+model+"\ncost: "+price+"\nservice station: "+station+"\n discount rate: "+rate);
}
public void discount(){
double rate2=price*rate;
double rate3=price-rate2;
System.out.println("Discount rate of the bike is "+rate3);
}
public static void main(String args[]){
bike bee=new bike();
super.display();
display();
bee.discount();
}
}
i wanna know why i can't access the shadowed method in the specified place of my code