Question

In general Describe when, where, and how is super keyword used in a constructor.

In general Describe when, where, and how is super keyword used in a constructor.

Homework Answers

Answer #1

Ans:-

Super keyword:-

* The super keyword refers to superclass (parent) objects. It is used inside a sub-class method definition to call a method defined in the super class. Private methods of the super-class cannot be called. Only public and protected methods can be called by the super keyword. It is also used by class constructors to invoke constructors of its parent class.

* The most common use of the super keyword is to eliminate the confusion between superclasses and subclasses that have methods with the same name. super() should be first statement inside any constructor. It can be used only inside constructor and nowhere else. super() is used to refer only parent class’s(super class’s) constructor.

* Super keyword (super() ) is used to call Base class’s constructor(i.e, Parent’s class).

How a super keyword used in a constructor can be understand by a simple program:-

class Parent {

    Parent()

    {

        System.out.println("Parent class's No " +

                              " arg constructor");

    }

}

class Child extends Parent {

    Child()

    {

        super();

        System.out.println("Flow comes back from " +

                        "Parent class no arg const");

    }

    public static void main(String[] args)

    {

        new Child();

        System.out.println("Inside Main");

    }

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
IN JAVA Inheritance Using super in the constructor Using super in the method Method overriding Write...
IN JAVA Inheritance Using super in the constructor Using super in the method Method overriding Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method in it. The following characteristics should be used: make, weight, height, length, maxSpeed, numberDoors, maxPassenges, isConvertable, numberSeats, maxWeightLoad, and numberAxels. Characteristics that are applicable to all vehicles should be instance variables in the Vehicle class. The others should be in the class(s) where they belong. Class vehicle should have...
Describe the General Sinusoidal function. When was the term “sinusoid” first used? Sinusoidal functions occur in...
Describe the General Sinusoidal function. When was the term “sinusoid” first used? Sinusoidal functions occur in other fields of study and nature. Give an example of an application of sinusoid modeling in real life. How might this be useful in your field of study? Be sure to cite any sources you use.
Describe the three categories of ratios used in ratio analysis. When working on assessing General Motors,...
Describe the three categories of ratios used in ratio analysis. When working on assessing General Motors, which of these ratios do you think is the most important indicator of successful performance, why?
Securline blood bank commercial armband system. Describe how that particular system is used, and explain the...
Securline blood bank commercial armband system. Describe how that particular system is used, and explain the general benefits for using an additional commercial armband when collecting specimens for pre-transfusion testing.
in a career setting, describe a situation where probability or discrete probability distributions are used. How...
in a career setting, describe a situation where probability or discrete probability distributions are used. How does a better understanding of these topics aid in the comprehension of your selected use. If possible, supplement your post with a graph or example from the web of this use.
In general, the terms favorable and unfavorable are used to describe the effect of a variance...
In general, the terms favorable and unfavorable are used to describe the effect of a variance on Select one: a. income/profit b. sales revenue c. production costs d. operating expenses e. balance sheet
Describe the general structure of eicosanoids and how they function in physiology.
Describe the general structure of eicosanoids and how they function in physiology.
Describe in general terms how a vectored vaccine is generated.
Describe in general terms how a vectored vaccine is generated.
Explain what Quantitative Easing means, how it works, where and when this policy was used. Was...
Explain what Quantitative Easing means, how it works, where and when this policy was used. Was QE an appropriate policy option? Can you suggest a different policy that could be used by the Fed or the Government to address the same problem?
Describe the inventory system mostly used in the industries where the number of input item used...
Describe the inventory system mostly used in the industries where the number of input item used in the manufacturing process are numerous. Don’t write more than 8 lines .