Solved

Class Animal

Question 22

Essay

class Animal
{  
    void myDog()  
    {  
        System.out.println("Animal stuff");  
    }  
}  
        
      
class Dog extends Animal
{  
     void mydog()  
    {  
        System.out.println("Dog stuff");  
    }  
    public static void main(String args[])  
    {  
        Dog d = new Dog();  
        d.myDog();  
        super.myDog();  
    }  
}
The above code gives a compiler error stating that the non-static variable super cannot be
referenced from a static context super.myDog(); . Explain why the error occurs and describe what changes you could make for the code to be executable.

Correct Answer:

verifed

Verified

The main method is static , and it can o...

View Answer

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions