Question

In a general sense describe when, where, and how is super keyword used in a method...

In a general sense describe when, where, and how is super keyword used in a method in java?

Homework Answers

Answer #1

The super keyword in java is a reference variable that is used to refer parent class objects. The keyword “super” came into the picture with the concept of Inheritance.

Use of super with methods: It is used when we want to call parent class method. So whenever a parent and child class have same named methods then to resolve ambiguity we use super keyword. This code snippet helps to understand the said usage of super keyword.

Understanding with the help of Java program:

In the below example, it can be seen that if we only call method message() then, the current class message() is invoked but with the use of super keyword, message() of superclass could also be invoked.

Important point:

  1. Call to super() must be first statement in Derived(Student) Class constructor.
  2. If a constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-argument constructor of the superclass. If the superclass does not have a no-argument constructor, you will get a compile-time error. Object does have such a constructor, so if Object is the only superclass, there is no problem.

JAVA Code Snapshot:

Output Snapshot:

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 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.
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 payback method in capital budgeting and how it is used?
describe payback method in capital budgeting and how it is used?
what is information gain? where is it used? what makes sense?
what is information gain? where is it used? what makes sense?
How can I think about matrix entries in a general sense? I a looking for a...
How can I think about matrix entries in a general sense? I a looking for a much deeper analysis than “systems of equations.” For instance, I know that when it is a rotation matrix, I know that the column vectors in the matrix, R, will be where the basis vectors land, and hence it will rotate any given vector accordingly. (is this correct in a general sense, as far as rotation matrices go?) However, for a general linear transformation, I...
What is the statistical conclusion when P<alpha (in the most general sense...not for a particular example)?
What is the statistical conclusion when P<alpha (in the most general sense...not for a particular example)?
The keyword static when applied to a field means what:    There is a copy of...
The keyword static when applied to a field means what:    There is a copy of the field for each class object.     The field may be accessed only by the constructor of the class.     Only one copy of the field in memory     The field is subject to garbage collection. What does it mean for a class method to be static?    It means the method is private.     It means the method is public.     It means...
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?
Describe why and when a “coin flip” method can be used for making decisions about clinical...
Describe why and when a “coin flip” method can be used for making decisions about clinical interventions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT