The code below gives a compile time error:non-static variable this cannot be referenced from a static context.
Could someone tell me where I've made a mistake? I'm new to programming so it would be great if you explain it step by step.
import java.util.*;
public class Dog{
int age;
String name;
public void BowBow(){
System.out.println("Bow Bow I'm Dog1");
}
public class Dog1 extends Dog{
int age1;
String name1;
public void owow(){
System.out.println("oow oow I'm Dog2");
}
}
public class Dog2 extends Dog1{
int age2;
String name2;
public void uhh(){
System.out.println("uhh uhh I'm Dog3");
}
}
public static void main(String [] args){
Dog1 obj1 = new Dog1();
Dog2 obj2 = new Dog2();
Dog2 obj3 = new Dog2();
obj1.age = 18;
obj1.name = "Hugo";
System.out.println("age:"+obj1.age);
System.out.println("Name:"+obj1.name);
obj2.age1 = 19;
obj2.name1 = "Huxley";
System.out.println("Age:"+obj2.age1);
System.out.println("Name:"+obj2.name1);
obj3.BowBow();
obj3.owow();
obj3.uhh();
}
}