CMU CPS 181 - Chapter 10 Review Questions

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is required for an interface method that has a body?

The method header must begin with the key word "default"

It is not possible for a superclass to call a subclass's method.

True

Which of the following is an example of a lambda expression?

int x = x*factor

Replacing inadequate superclass methods with more suitable subclass methods is known as ________.

method overriding

The ________ key word is used to call a superclass constructor explicitly.

super

Does "public class Salaried extends PayType" declare Salaried as a subclass of PayType?

heck yeah it does

If a class contains an abstract method ________.

the method will only have a header, no body, will end with a semicolon, and method cannot be overridden in subclasses. You must also create an instance of the class

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.

________ is a special type of expression used to create an object that implements a functional interface.

Lambda

In the following code, which line has an error? Line 1 public interface Interface1 Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double){} Line 5 }

Line 4

All methods specified by an interface are ________.

Public

(T/F) Every class has a toString method and an equals method inherited from the Object class.

TRUE

In a class hierarchy ________.

General classes = toward the lovely top branches Specialized classes = toward the roots

(T/F) A compiler error will result if an anonymous inner class tries to use a variable that is not final, or not effectively final.

TRUE

Given the following code: Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public void method1(int a){} Line 5 } Line 6 public class ClassB extends ClassA Line 7 { Line 8 public ClassB(){} Line 9 public void method1(){} Line 10 } Line 11 public class ClassC extends ClassB Line 12 { Line 13 public ClassC(){} Line 14 public void method1(){} Line 15 } Which method1 will be executed when the following statements are executed?

method1 on line 9

(T/F) A functional interface is simply an interface that has one abstract method.

TRUE

(T/F) An abstract class is not instantiated itself but serves as a superclass for other classes.

TRUE

(T/F) Because every class directly or indirectly inherits from the Object class, every class inherits the Object class's members.

TRUE

(T/F) Because the subclass is more specialized than the superclass, it is sometimes necessary for the subclass to replace inadequate superclass methods with more suitable ones.

TRUE

In ________, inheritance is shown with a line that has an open arrowhead at one end that points to the superclass.

a UML diagram

(T/F) public class ClassB implements ClassA{ } ClassB must override each method in ClassA.

TRUE

(T/F)If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method.

TRUE

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

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

@Override

A(n) ________ method is a method that appears in a superclass but expects to be overridden in a subclass.

Abstract

When an "is a" relationship exists between objects, the specialized object has ________.

All of the characteristics of the general object plus additional characteristics

All fields declared in an interface ________

Are treated as final and static

When a subclass overloads a superclass method ________.

Both methods may be called with a subclass object

(T/F) All methods in an abstract class must also be declared abstract.

FaLsE

In the following code, what is missing from ClassA? Line 1 public interface MyInterface Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double); Line 5 } Line 6 public class ClassA implements MyInterface Line 7 { Line 8 FIELDA = 60; Line 9 public int methodB(double) { } Line 10 }

It does not override methodA

In the following code, what will the call to super do? public class ClassB extends ClassA { public ClassB() { super(40); System.out.println("This is the last statement "+ "in the constructor."); } }

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

In the following code, which line will cause a compiler error? Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public int method1(int a){} Line 5 public final int method2(double 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 }

Line 11

A class becomes abstract when you place the ________ key word in the class definition.

abstract

Which of the following shows the inheritance relationships among classes in a manner similar to that of a family tree?

class hierarchy

Which key word indicates that a class inherits from another class?

extends

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

final

If you don't provide an access specifier for a class member, the class member is given ________ access by default.

package

What type of relationship exists between two objects when one object is a specialized version of another object?

"is a"

Protected class members can be denoted in a UML diagram with the ________ symbol.

#

A protected member of a class may be directly accessed by ________.

Methods of the same class, methods of the same package, and methods of a subclass

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 a method in a subclass has the same signature as a method in the superclass, the subclass method ________ the superclass method.

Overrides

In Java, a reference variable is ________ because it can reference objects of types different from its own, as long as those types are related to its type through inheritance.

Polymorphic

In an inheritance relationship ________.

The superclass constructor always executes before the subclass constructor

(T/F) Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package

True

(T/F) When a subclass overrides a superclass method, only the subclass's version of the method can be called with a subclass object.

True

(T/F) You can write a super statement that calls a superclass constructor but only in the subclass's constructor.

True

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

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

ClassC

If ClassC is derived from ClassB, which is derived from ClassA, this would be an example of___

Chain of inheritance

(T/F) If two methods in the same class have the same name but different signatures, the second overrides the first.

FaLsE

(T/F) Inheritance involves a subclass, which is the general class, and a superclass, which is the specialized class.

FaLsE

(T/F)In an inheritance relationship, the subclass constructor always executes before the superclass constructor.

FaLsE

A ________ member's access is somewhere between public and private.

Protected

Does "public class ClassA implements Interface1, interface2" correctly specify two interfaces?

Yess

Which of the following is the operator used to determine whether an object is an instance of a particular class?

instanceOf

In the following code, which line in ClassA has an error? Line 1 public interface MyInterface Line 2 { Line 3 int FIELDA = 55; Line 4 public int methodA(double); Line 5 } Line 6 public class ClassA implements MyInterface Line 7 { Line 8 FIELDA = 60; Line 9 public int methodA(double) { } Line 10 }

Line 8

A subclass may call an overridden superclass method by ________.

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

When declaring class data members it is best to declare them as ________.

Private members

(T/F) When a subclass extends a superclass, the public members of the superclass become public members of the subclass.

TRUE


Conjuntos de estudio relacionados

Chapter 23 -give me liberty all study questions/ chronological

View Set

AHIV EXAM 4 & AHIII EXAM 5 | CH 41 Stroke |

View Set

Judicial Process Study Questions Part 1 (1-80)

View Set

Investment Analysis- Risk and Return

View Set

Semester 2 Living a Godly Life (Male)

View Set

Abeka Spanish 1 Test 12/Final Exam

View Set

Sorting Algorithms (n = # of records to be sorted)

View Set

Lesson 5 Speedback Assignment - History from 1877

View Set