Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a supertype method?

I have googled couple of times but still can't understand the supertype method. Can anyone please explain what is this?

like image 687
ray Avatar asked Feb 28 '13 07:02

ray


2 Answers

There is a notion of supertype and subtype in OOPS, In java this kind of relationship is implemented by inheritance i.e. using extends keyword:

class A {} // super class
class B extends A {} //sub class

Any member (fields, methods) declared in super class is to be called supertype.

Therefore in above context if class A has method like

class A {
   void set()
}

Set is supertype method for class B.

However, notice that if there is another class say C:

class C {
    void set()        
}

Then set() method is not supertype for C class because there is no relationship between class A and class C (relationship is created by extends keyword, for inheritance).

like image 149
navyad Avatar answered Sep 20 '22 13:09

navyad


if you are talking about calling a super method, you should try the following

  1. Create a class with a method public method e.g. printSomething()
    public void printSomething() {
       System.out.println("hello, I am the first class");
     }
    
  2. Create a second class which inherites from the first class and override the printSomething method
    @override
    public void printSomething() {
    super.printSomething();
    }
    
  3. Write a small programme which call the method printSomething of class two and see what will happen
like image 38
Michael Meyer Avatar answered Sep 17 '22 13:09

Michael Meyer