Java: Chapter 10

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Protected class members are denoted in a UML diagram with the symbol

A) #

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

A) ClassA

Look at 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? ClassA item1 = new ClassB(); item1.method1();

A) Line 9

What is wrong with the following code? IntCalculator square = new IntCalculator() { public int calculate(int number) { return number + number; }}

A) The statement does not end with a semicolon.

In an inheritance relationship

A) The superclass constructor always executes before the subclass constructor

When one object is a specialized version of another object, there is this type of relationship between them.

D) is a

If ClassA extends ClassB, then

D) public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA

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 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 }

D) 11

Look at 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

D) 4

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

D) ClassB

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

D) IntCalculator multiplier = x and x * factor;

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

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

Look at 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 method will be executed when the following statements are executed? ClassC item1 = new ClassA(); item1.method1();

D) This is an error and will cause the program to crash.

When an "is a" relationship exists between objects, it means that the specialized object has

all the characteristics of the general object, plus additional characteristics

All fields declared in an interface

are final and static

An anonymous inner class must

either implement an interface or extend another class

Look at 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 }

B) 8

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

B) @Override

When a subclass overloads a superclass method

B) Both methods may be called with a subclass object

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

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

If a subclass constructor does not explicitly call a superclass constructor

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

A subclass can directly access:

only public and protected members of the superclass

A subclass may call an overridden superclass method by:

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

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

A) final

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

A) private members

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

A) super

Look at 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 as a result of the following statements? ClassA item1 = new ClassC(); item1.method1();

B) Line 14

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

B) Method overriding

What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { super (40); System.out.println("This is the last statement " + "in the constructor."); } }

B) Nothing is wrong with the code.

Which of the following is TRUE about protected access?

B) Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package.

If ClassC extends ClassB, which extends ClassA, this would be an ex

B) a chain of inheritance

The super statement that calls the superclass constructor:

B) must be the first statement in the subclass's constructor

If a class contains an abstract method

B) 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

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

Look at 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 }

C) It does not override methoda.

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

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

This is a variable whose value is never changed, but it isn't declared with the final key word.

C) effectively final variable

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

C) overloaded

In an interface all methods have

C) public access

Given the following code which of the following is TRUE? public class ClassB implements ClassA{}

ClassB must override each method in ClassA.

In UML diagrams, inheritance is shown

D) With a line that has an open arrowhead at one end that points to the superclass

Like a family tree, a ________ shows the inheritance relationship between classes.

D) class hierarchy

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

A) The method header must begin with the key word default.


Set pelajaran terkait

POST TEST 3- Introduction to Joint Multi-TDL Network Operations

View Set

Chapter 01: The Health Care System

View Set

Testout Server Pro: Install and Configure 3.1.0 Chapters: 1,3,4,5,6,7,8,9,10

View Set

ISSA Personal Training- Section 1 Final

View Set