ITP 120 - Chapter 10 QUIZ

Ace your homework & exams now with Quizwiz!

Which of the following statements declares Salaried as a subclass of PayType?

public class Salaried extends PayType

What key word can you use to call a superclass constructor explicitly?

super

If a class contains an abstract method:

the method will have only a header, but not a body, and end with a semicolon

If a superclass does not have a default constructor or a no-arg constructor:

then a class that inherits from it, must call one of the constructors that the superclass does have.

Look at the following code and determine what the call to super will do. public class ClassB extends ClassA { public ClassB() { super(10); } }

It will call the constructor of ClassA that receives an integer as an argument.

What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { int init = 10; super(40); } }

The call to the method super must be the first statement in the constructor.

When a method is declared with the ________ modifier, it cannot be overridden in a subclass.

final

This annotation tells the Java compiler that a method is meant to override a method in the superclass.

@Override

A protected member of a class may be directly accessed by:

All of these

In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC

ClassA

In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC

ClassB

Replacing inadequate superclass methods with more suitable subclass methods is known as what?

Method overriding

A subclass can directly access:

only public and protected members of the superclass

If two methods have the same name but different signatures, they are:

overloaded

If you do not provide an access specifier for a class member, the class member is given ________ access by default.

package

A subclass may call an overridden superclass method by:

prefixing its name with the super key word and a dot (.)

Look at the following code. Which line will cause a compiler error? Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public final int method1(int a){} Line 5 public double method2(int b){} Line 6 } Line 7 public ClassB extends ClassA Line 8 { Line 9 public ClassB(){} Line 10 public int method1(int b){} Line 11 public double method2(double c){} Line 12 } 10

10

Look at the following code. The method in line ________ will override the method in line __________. Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public int method1(int a){} Line 5 public int method2(int b){} Line 6 } Line 7 public ClassB extends ClassA Line 8 { Line 9 public ClassB(){} Line 10 public int method1(int b){} Line 11 public int method2(double c){} Line 12 }

10, 4

If a subclass constructor does not explicitly call a superclass constructor:

Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes


Related study sets

CH15_SIM File System and its Data Acquisition Method

View Set

Texas Real Estate Exam Practice Question

View Set

chapter 16 therapy and treatment

View Set

Chapter 14 Substance-Related and Addictive Disorders

View Set

Texas 30-Hour Promulgated Contract Forms with Flex Units

View Set