COP 2800 Chapter 10

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

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

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

Correct The statement does not end with a semicolon.

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

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

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

True

When a subclass extends a superclass, the public members of the superclass become public members of the subclass.

private members

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

Correct Nothing is wrong with the code.

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."); } }

False

All methods in an abstract class must also be declared abstract.

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

If ClassA extends ClassB, then:

a chain of inheritance

If ClassC extends ClassB, which extends ClassA, this would be an example of:

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

If a class contains an abstract method:

False

If a method in a subclass has the same signature as a method in the superclass, the subclass method overloads the superclass method.

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

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

10

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 }

Correct Method overriding

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

must be the first statement in the subclass's constructor

The super statement that calls the superclass constructor:

lambda

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

effectively final variable

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

ClassB

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

Line 9

Look at the following code: Line 1 public class ClassA Line 2 { Line 3 public ClassA() {} Line 4 public void method1(){} 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();

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

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();


संबंधित स्टडी सेट्स

Measuring the force of earthquakes

View Set

(A2.6) - Dar las gracias y responder " de nada"

View Set

GCSE/A Level Computing Hexadecimal Numbers

View Set

Quiz #5. - Ch. 4 (Repetition) - [C Programming I]

View Set

HW: electric charges and coulomb's law

View Set

placenta, umbilical cord, amniotic fluid and membrane pathology

View Set

Chapter 12: Nursing Management During Pregnancy

View Set

Philosophy (THE HUMAN PERSON IN SOCIETY)

View Set

Isosceles Triangles Assignment and Quiz

View Set