• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/3

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

3 Cards in this Set

  • Front
  • Back

Will the following compile?

class Car {
Car (String s) { System.out.print("Car");}
}




public class Ferrari extends Car {
public Ferrari(String s) {System.out.print("B");}


public static void main(String [] args) {


new Ferrari("C");


System.out.println(" ");


}


}

No

Car does not have a no-arg constructor. However the constructor for Ferrari has an implied call to the super constructor, this call has no arguments. The lack of the no-arg constructor for Car causes the compilation error.

Will the following compile?




class Car {
Car (String s) { System.out.print("Car");}
}




public class Ferrari extends Car {
public Ferrari(String s) { super("abc"); System.out.print("B");}


public static void main(String [] args) {


new Ferrari("C");


System.out.println(" ");


}


}

Yes




The constructor for Ferrari actually calls the super class constructor explicitly, and passes in the required arguments. If you were to remove the call to super("abc"), it would fail compilation.