Java Reference
In-Depth Information
Inside AOSuper.print()
Inside AOSub.print()
Inside AOSuper.print()
There is no way to directly call a method of the superclass of the superclass. You can call the overridden method
of the superclass (only the immediate ancestor) using the keyword super . Suppose there are three classes: A , B , and
C , where class B inherits from class A , and class C inherits from class B . There is no way to call methods of class A from
inside class C . If class C needs to call a method of class A , you need to provide a method in class B that will call method
of class A . Class C will call the method of class B , which in turn will call the method of class A .
When a method call is made using the keyword super , Java uses early binding, even though the method is an
instance method. another instance when Java uses early biding for an instance method call is a private method call
because a private method cannot be invoked from outside its defining class. a private method cannot be overridden
either. the keyword super refers to the instance fields and methods or constructors of the immediate ancestor of the
class in which it appears.
Tip
Method Overloading
Having more than one method with the same name in the same class is called method overloading. Methods with the
same name in a class could be declared methods, inherited methods, or a combination of both. Overloaded methods
must have different number of parameters, different types of parameters, or both. The return type, access level and
throws clause of a method play no role in making it an overloaded method. The m1() method of the OME1 class is an
example of an overloaded method.
public class OME1 {
public void m1(int a) {
// Code goes here
}
public void m1(int a, int b) {
// Code goes here
}
public int m1(String a) {
// Code goes here
}
public int m1(String a, int b) throws CheckedException1 {
// Code goes here
}
}
 
 
Search WWH ::




Custom Search