0
0
Javaprogramming~5 mins

Super keyword in Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the super keyword in Java?
The <code>super</code> keyword is used to refer to the parent class of the current object. It helps access parent class methods, constructors, and variables.
Click to reveal answer
beginner
How do you call a parent class constructor using <code>super</code>?
You call a parent class constructor by writing <code>super(arguments);</code> as the first line inside the child class constructor.
Click to reveal answer
intermediate
Can <code>super</code> be used to access parent class variables if they are hidden by child class variables?
Yes, <code>super.variableName</code> accesses the parent class variable when the child class has a variable with the same name.
Click to reveal answer
intermediate
What happens if you don't explicitly call <code>super()</code> in a child class constructor?
Java automatically inserts a call to the no-argument parent constructor super() if you don't call it explicitly. If the parent has no no-arg constructor, it causes a compile-time error.
Click to reveal answer
beginner
Can super be used to call overridden methods in the parent class?
Yes, <code>super.methodName()</code> calls the parent class version of a method that is overridden in the child class.
Click to reveal answer
What does super() do inside a child class constructor?
ACalls the child class constructor
BCreates a new object
CCalls a method named super
DCalls the parent class constructor
How do you access a parent class variable hidden by a child class variable?
AUse <code>super.variableName</code>
BUse <code>this.variableName</code>
CUse <code>parent.variableName</code>
DUse <code>variableName()</code>
If a parent class has no no-argument constructor, what happens if the child constructor does not call super() explicitly?
ACode compiles fine
BCode throws a runtime exception
CCode fails to compile
DParent constructor is called automatically with arguments
Which of these can super NOT be used for?
ACreating new objects
BAccessing parent class variables
CCalling parent class methods
DCalling parent class constructors
How do you call a parent class method that is overridden in the child class?
A<code>this.methodName()</code>
B<code>super.methodName()</code>
C<code>parent.methodName()</code>
D<code>methodName()</code>
Explain how the super keyword helps in constructor chaining in Java inheritance.
Think about how child and parent constructors work together.
You got /4 concepts.
    Describe how super can be used to access hidden variables and overridden methods in a child class.
    Consider when child class has same names as parent.
    You got /4 concepts.