• 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/52

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;

52 Cards in this Set

  • Front
  • Back

In an inheritance relationship, this is the general class. a. subclass b. superclass c. slave class d. child class

1. b

In an inheritance relationship, this is the specialized class.a. superclassb. master classc. subclassd. parent class

2. c

This key word indicates that a class inherits from another class. a. derived b. specialized c. based d. extends

3. d

A subclass does not have access to these superclass members.a. publicb. privatec. protectedd. all of these

4. b

This key word refers to an object’s superclass. a. super b. base c. superclass d. this

5. a

In a subclass constructor, a call to the superclass constructor must __________. a. appear as the very first statement b. appear as the very last statement c. appear between the constructor’s header and the opening brace d. not appear

6. a

The following is an explicit call to the superclass’s default constructor.a. default();b. class();c. super();d. base();

7. c

A method in a subclass that has the same signature as a method in the superclass is anexample of __________.a. overloadingb. overriding c. compositiond. an error

8. b

A method in a subclass having the same name as a method in the superclass but a differentsignature is an example of __________.a. overloadingb. overridingc. compositiond. an error

9. a

These superclass members are accessible to subclasses and classes in the same package.a. privateb. publicc. protectedd. all of these

10. c

All classes directly or indirectly inherit from this class.a. Objectb. Superc. Rootd. Java

11. a

With this type of binding, the Java Virtual Machine determines at runtime which method to call, depending on the type of the object that a variable references. a. static b. early c. flexible d. dynamic

12. d

This operator can be used to determine whether a reference variable references an object of a particular class. a. isclass b. typeof c. instanceof d. isinstance

13. c

When a class implements an interface, it must __________.


a. overload all of the methods listed in the interface b. provide all of the nondefault methods that are listed in the interface, with the exact signatures and return types specified c. not have a constructor d. be an abstract class

14. b

Fields in an interface are __________.a. finalb. staticc. both final and staticd. not allowed

15. c

Abstract methods must be __________.a. overriddenb. overloadedc. deleted and replaced with real methodsd. declared as private

16. a

Abstract classes cannot __________.a. be used as superclassesb. have abstract methodsc. be instantiatedd. have fields

17. c

You use the __________ operator to define an anonymous inner class.a. classb. innerc. newd. anonymous


An anonymous inner class must __________.a. be a superclassb. implement an interfacec. extend a superclassd. either b or c.

A functional interface is an interface with __________.a. only one abstract method.b. no abstract methods.c. only private methods.d. no name


You can use a lambda expression to instantiate an object that __________. a. that has no constructor. b. extends any superclass. c. implements a functional interface d. does not implement an interface.


True or False: Constructors are not inherited.

True

True or False: In a subclass, a call to the superclass constructor can only be written in the subclass constructor.

True

True or False: If a subclass constructor does not explicitly call a superclass constructor, Java will not call any of the superclass’s constructors.

False

True or False: An object of a superclass can access members declared in a subclass.

False

True or False: The superclass constructor always executes before the subclass constructor.

True

True or False: When a method is declared with the final modifier, it must be overridden in a subclass.

False

True or False: A superclass has a member with package access. A class that is outside the superclass’s package but inherits from the superclass can access the member.

False

True or False: A superclass reference variable can reference an object of a subclass that extends the superclass

True

True or False: A subclass reference variable can reference an object of the superclass.

False

True or False: When a class contains an abstract method, the class cannot be instantiated.

True

True or False: A class may only implement one interface.

False

True or False: By default all members of an interface are public

True

// Superclass


public class Vehicle{ (Member declarations . . .)}


// Subclass


public class Car expands Vehicle{ (Member declarations . . .)}

The Car classheader should use the word extendsinstead of expands.

// Superclass


public class Vehicle{ private double cost; (Other methods . . .)}


// Subclass


public class Car extends Vehicle{ public Car(double c) { cost = c; }}

The Car class constructor cannot access the Vehicle class's cost field.

// Superclass


public class Vehicle{ private double cost; public Vehicle(double c) { cost = c; } (Other methods . . .)}


// Subclass


public class Car extends Vehicle


{ private int passengers; public Car(int p) { passengers = c; } (Other methods . . .)}

Because the Vehicle class does not have a default constructor or a no-arg constructor, the Car class constructor must call the Vehicle class constructor.

// Superclass


public class Vehicle{ public abstract double getMilesPerGallon(); (Other methods . . .)}


// Subclass


public class Car extends Vehicle{ private int mpg; public int getMilesPerGallon(); { return mpg; } (Other methods . . .)}

The getMilesPerGallon method in the Car class should return a double.

What is an “is-a” relationship?

When an “is a” relationship exists between objects, it means that the specialized object has all of the characteristics of the general object, plus additional characteristics that make it special.

A program uses two classes: Animal and Dog. Which class is the superclass and which is the subclass?

The superclass is Animal and the subclass is Dog.

What is the superclass and what is the subclass in the following line? public class Pet extends Dog

Dog is the superclass and Pet is the subclass.

What is the difference between a protected class member and a private class member?

A protected member of a class may be directly accessed by methods of the same class or methods of a subclass. In addition, and this is how protected members are different from private members, protected members may be accessed by methods of any class that are in the same package as the protected member’s class. A protected member is not quite private, because it may be accessed by some methods outside the class.

Can a subclass ever directly access the private members of its superclass?

No.

Which constructor is called first, that of the subclass or the superclass?

The superclass.

What is the difference between overriding a superclass method and overloading a superclass method?

Overloading is when a method has the same name as one or more other methods, but a different parameter list. Although overloaded methods have the same name, they have different signatures. When a method overrides another method, however, they both have the same signature.

Reference variables can be polymorphic. What does this mean?

A superclass reference variable can reference objects of classes that inherit from the superclass.

When does dynamic binding take place?

At runtime.

What is an abstract method?

An abstract method is a method that appears in a superclass, but expects to be overridden in a subclass. An abstract method has only a header and no body.

What is an abstract class?

11. An abstract class is not instantiated itself, but serves as a superclass for other classes. The abstract class represents the generic or abstract form of all the classes that inherit from it.

What are the differences between an abstract class and an interface?

A class can inherit from only one superclass, but Java allows a class to implement multiple interfaces.

When you instantiate an anonymous inner class, the class must do one of two things. What are they?

NA

What is a functional interface?

NA

What is a lambda expression?

Anonymous Classes. Before lambda expressions, anonymous inner classes were an option. For example, an interface ( MyTest.java ) written with one test method that returns a boolean (a functional interface) is a possible solution. The search criteria could be passed when the method is called.Ref#Google