This is the code I'm practicing for multilevel inheritence, but when I run it the online compiler gives me following errors:
public class MyClass {
^
/grandFather.java:26: error: non-static method talking() cannot be referenced from a static context
son.talking();
^
/grandFather.java:27: error: non-static method walking() cannot be referenced from a static context
son.walking();
^
/grandFather.java:28: error: non-static method running() cannot be referenced from a static context
son.running();
This is the code I'm running. It's a practice code for multilevel inheritence in java. I have created 3 class(grandFather, father and son):
public class grandFather{
int age;
double height;
public void talking(){
System.out.println("Grandfather can walk");
}
}
class father extends grandFather{
public void walking(){
System.out.println("Father can walk too");
}
}
class son extends father{
public void running(){
System.out.println("Son can talk, walk and also run");
}
}
public class MyClass {
public static void main(String args[]) {
son kamran = new son();
son.talking();
son.walking();
son.running();
}
}