×

Loading...

We can use inherited methods only in the definition of the sub class.

This is a flaw in Java. Once a subclass extends a superclass, there is
NO WAY to use the methods of the super class. We can use inherited methods ONLY
in the definition of the subclass. Please look at the following toy code.


class Daddy{
public void smoke(){
System.out.println("Cigar! Cigar!");
}
}

class Sonny extends Daddy{
public void smoke(){
//This calling of inherited methods is OK!
super.smoke();
System.out.println("Marlboro! Marlboro!!");
}
}

public class Test{
Sonny sonny = new Sonny();
sonny.smoke();
// The following code does not work!
//sonny.super.smoke();
}
}
Report

Replies, comments and Discussions: