Skip to main content

Program to demonstrate the use of 'super' keyword


class TestSuper1
   {
    int x =10;
    TestSuper1(int p)
       {
        System.out.println("Super class Argumented Constructor");
       }
    void demo()
       {
        System.out.println("Super class");
       }
   }
class SuperTest1 extends TestSuper1
   {
    int x=100;
    SuperTest1()
       {
        // super class constructor using super
        super(1);
        System.out.println("Sub-class Constructor");

       }

    public static void main(String rks[])
       {
       
        SuperTest1 t = new SuperTest1();
        t.demo();
       }

    void demo()
       {
        System.out.println("Sub-class Demo");
        // super class method using super
        super.demo();
        System.out.println("Sub-class x: "+ x);
        // super class data member x using super
        System.out.println("Super class x: "+ super.x);
       
       }

   }

Comments

  1. Thanks for this article. It's just what I was searching for. I am always interested in this subject.

    PIC scheme

    ReplyDelete
  2. Super keyword in java

    Thanks for this post, it helpful for me and my all friends

    ReplyDelete
  3. Good Post! Thank you so much for sharing the nice post, it was so good to read and useful to improve
    Java Training in Electronic City

    ReplyDelete

Post a Comment

Popular posts from this blog

ETE Practice Set-1

                                                                 Mock Test-1 -----------------------------------------------------------------------------------------------------------------------------   1 (a) Write a program that reads 10 integers between 1 and 100 and counts the occurrences of each. Assume the input ends with 0.                                                         ...

Practice Set: Unit-4

                                                                                                                Practice Set: Unit 4 1. What are the uses of super keyword in Java? Explain with a suitable example. 2. What are the various uses of final keyword in java? An abstract method can not be declared final. Why? 3. Differentiate between Abstract class and Interface. What do you mean by Functional interface and Lambda Expression?  ...

OLA-UBER Problem

Create two interfaces OLA and UBER both having a method public static Cab getCab() which returns the Cab object where Cab is a nested class inside OLA and UBER. Cab must have attributes cab_number and driver_name. A user rides 5 times using cabs of OLA and UBER randomly which are stored in an array. Now implement a method which should display the name of the driver and the company name i.e. OLA/UBER when the valid cab_number is entered by the user. Display "Invalid CAB details" when the cab_number entered by the user is incorrect.