Inheritance in Object-Oriented Programming
For which reason might one deliberately choose not to use ‘super’ keyword whilst coding within subclass's methods?
Because using 'super' always causes runtime errors due to improper coverage of code exceptions handling
Because 'super' keywords cannot be compiled in Java programs at all
Due to preventing access to private members of other unrelated classes outside hierarchy
Avoid accidental overridings if we wish to use or modify current class's functionality instead of accessing parent class
In what scenario would compiling fail due to improper use of 'super' keyword within a Java program containing several levels of inheritance?
Using super call inside a standalone method that doesn't override a similar method from superclass.
Passing arguments through super('args') that match none of the constructors available in immediate parent.
Placing a 'super' call at the end rather than start of constructor body in subclass definition.
Attempting to call grandparent's overloaded constructor not present in parent from subclass.
Given the block of code below, answer the following question:
java
class Shape {
// constructor not shown
public void draw() {
System.out.println("Drawing a shape");
}
}
class Circle extends Shape {
// constructor not shown
public void draw() {
System.out.println("Drawing a ci...
"Drawing a circle" followed by "Drawing a shape"
"Drawing a shape" followed by "Drawing a circle"
"Drawing a shape"
"Drawing a circle"
In a complex inheritance hierarchy where Class B extends Class A, and Class C extends B, which invocation within class C’s constructor will correctly call a non-default superclass constructor of A?
this()
super.super()
super()
B()
What does 'super()' do when it appears as the first statement in a subclass's constructor?
It initializes all instance variables of its subclass with default values.
It ensures that all methods in the subclass will be overridden by those in its superclass.
It calls the no-argument constructor of its superclass.
It creates an instance of its superclass separate from an instance of its subclass.
What is the difference between super()
and super.method()
in Java?
Both super()
and super.method()
are used to call the constructor of the superclass.
Both super()
and super.method()
are used to call a method from the superclass.
super()
is used to call the constructor of the superclass, while super.method()
is used to call a method from the superclass.
super()
is used to call a method from the superclass, while super.method()
is used to call the constructor of the superclass.
If a method of a superclass is overridden in the subclass, which method is called by the line "methodName();" in the subclass?
The method of the subclass.
Both methods will be called in sequence.
The method of the superclass.
An error will occur due to ambiguity.

How are we doing?
Give us your feedback and let us know how we can improve
What indicates the highest level of computational inefficiency when using the 'super' keyword within deeply nested inherited structures with complex algorithms?
Using 'super' conservatively for necessary utility functions while minimizing algorithmic complexity in overrides.
Employing 'super' selectively when it reduces duplication of logic-intensive code segments across subclasses.
Overriding each superclass's method only to add expensive computations before calling 'super'.
Implementing critical sections via 'super' calls that simplify control flow by delegating work upwards without added complexity.
In a Java program, the "super" keyword can be used to do which of the following?
Invoke the superclass's constructors and methods
Invoke only the superclass's methods
Invoke only the superclass's constructors
The "super" keyword does not exist in Java
Consider the code below. If we create an object of the Child class and call the printMessage()
method on that object, what will happen?
java
class Parent {
void printMessage() {
System.out.println("Hello from Parent");
}
}
class Child extends Parent {
void printMessage() {
...
"Hello from Parent" will be printed, followed by "Hello from Child."
The program will crash with a StackOverflowError
.
Hello from Child will be printed, followed by "Hello from Parent."
Only "Hello from Parent" will be printed.