Java Chapter 10-16 Flashcards
21 Questions
100 Views

Java Chapter 10-16 Flashcards

Created by
@SustainableAntigorite1088

Questions and Answers

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

True

A functional interface is simply an interface that has one abstract method.

True

An abstract class is not instantiated, but serves as a superclass for other classes.

True

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

<p>False</p> Signup and view all the answers

Every class has a toString method and an equals method inherited from the Object class.

<p>True</p> Signup and view all the answers

Every class is either directly or indirectly derived from the Object class.

<p>True</p> Signup and view all the answers

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

<p>False</p> Signup and view all the answers

If two methods in the same class have the same name but different signatures, the second overrides the first.

<p>False</p> Signup and view all the answers

Inheritance involves a subclass, which is the general class, and a superclass, which is the specialized class.

<p>False</p> Signup and view all the answers

In an inheritance relationship, the subclass constructor always executes before the superclass constructor.

<p>False</p> Signup and view all the answers

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

<p>True</p> Signup and view all the answers

Private members of the superclass cannot be accessed by the subclass.

<p>True</p> Signup and view all the answers

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

<p>True</p> Signup and view all the answers

When an interface variable references an object, you can use the interface variable to call any and all of the methods in the class implementing the interface.

<p>False</p> Signup and view all the answers

A subclass can directly access:

<p>Only public and protected members of the superclass</p> Signup and view all the answers

A subclass may call an overridden superclass method by:

<p>Prefixing its name with the super keyword and a dot (.)</p> Signup and view all the answers

All fields declared in an interface:

<p>Are final and static</p> Signup and view all the answers

An anonymous inner class must:

<p>Either implement an interface or extend another class</p> Signup and view all the answers

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

<p>ClassB must override each method in ClassA.</p> Signup and view all the answers

If a class contains an abstract method:

<p>The method will have only a header, but not a body, and end with a semicolon.</p> Signup and view all the answers

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

<p>Then a class that inherits from it must call one of the constructors that the superclass does have.</p> Signup and view all the answers

Study Notes

Compiler Errors and Variables

  • Anonymous inner classes can use variables only if they are final or effectively final. Using non-final variables will lead to compiler errors.

Functional Interfaces

  • A functional interface is defined as an interface with exactly one abstract method.

Abstract Classes

  • Abstract classes cannot be instantiated and serve as a foundation for derived classes.
  • Not all methods in an abstract class need to be declared as abstract; some can have a concrete implementation.

Object Class Methods

  • Every Java class inherits a toString method and an equals method from the Object class.
  • All classes in Java are ultimately derived from the Object class.

Method Overloading and Overriding

  • If a method in a subclass shares the same signature with a superclass method, it overrides, not overloads, the superclass method.
  • Overloading occurs when methods within the same class share names but have different signatures, while overriding represents method redefinition in subclasses.

Inheritance Relationships

  • Inheritance features a superclass (general class) and a subclass (specialized class), opposite to the incorrect assertion that a subclass serves as a general class.
  • The superclass constructor executes before the subclass constructor in an inheritance hierarchy.

Access Modifiers in Inheritance

  • Superclass methods cannot call subclass methods directly.
  • Private members in a superclass are inaccessible to subclasses.
  • Public members of a superclass become public members in the subclass.

Interface Variables and Methods

  • When an interface variable references an object, not all methods from the implementing class can be called; only those defined by the interface can be accessed.
  • Interface variables are inherently final and static, meaning they cannot be changed once initialized.

Inner Classes

  • Anonymous inner classes must either extend another class or implement an interface.

Class Implementation and Inheritance

  • If a class implements an interface (e.g., public class ClassB implements ClassA{}), it is required to override every abstract method defined in that interface.
  • Classes containing abstract methods must define those methods with only a header, omitting the implementation details.

Constructor Behavior

  • A subclass inheriting from a superclass without a default constructor must explicitly call one of the available constructors in the superclass to ensure proper instantiation.

Summary of Public Access

  • A subclass has access to only the public and protected members of its superclass but cannot access private members.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Description

Test your knowledge of Java concepts with this quiz covering chapters 10 through 16, including compiler errors and functional interfaces. Designed for students to review key definitions and true/false statements related to Java's advanced features. Perfect for a final exam preparation or a quick revision session.

More Quizzes Like This

Use Quizgecko on...
Browser
Browser