AP CSA inheritance flashcards

Study essential concepts of inheritance in AP Computer Science A with these flashcards and quizzes.

Amelia2004·19 Karteikarten·14 Fragen
APcomputer_scienceprogramming
0
Gewusst
1 / 19
0
Lerne noch
Vorderseite

What is inheritance in Java?

Tippen zum Umdrehen
Rückseite

Inheritance is a mechanism where one class inherits fields and methods from another class.

Tippen zum Umdrehen
Gewusst
Lerne noch

Quiz(14 Fragen)

Frage 1 von 14

1. What does the 'extends' keyword indicate?

Begriffe in diesem Lernset(19)

What is inheritance in Java?

Inheritance is a mechanism where one class inherits fields and methods from another class.

True or false: Subclasses can have their own methods.

True, because subclasses can define new methods in addition to inherited ones.

Difference between superclass and subclass?

The superclass is the parent class, while the subclass is the child class that inherits from it.

Define polymorphism.

Polymorphism allows methods to do different things based on the object that it is acting upon.

What keyword is used for inheritance?

The keyword 'extends' is used in Java to indicate that one class is inheriting from another.

Fill in the blank: A subclass inherits methods from its ______.

superclass.

True or false: A subclass can access private members of its superclass.

False, because private members are not accessible outside their own class.

What is a derived class?

A derived class is another term for a subclass which inherits properties and behaviors from a superclass.

What happens if a subclass overrides a method?

The subclass version of the method is called instead of the superclass method.

What is method overriding?

Method overriding occurs when a subclass provides a specific implementation of a method already defined in its superclass.

Difference between method overloading and overriding?

Overloading is defining multiple methods with the same name but different parameters; overriding is redefining a method in a subclass.

What is a constructor in inheritance?

A constructor initializes a new object. Subclasses can call the superclass constructor using 'super()'.

True or false: All classes in Java inherit from Object.

True, because Object is the root of the class hierarchy in Java.

What method is called when an object is created?

The constructor of the class is called.

Fill in the blank: Inheritance promotes ______ reuse.

code.

What is a multi-level inheritance?

Multi-level inheritance is when a class is derived from another derived class.

True or false: Java supports multiple inheritance.

False, because Java does not allow a class to inherit from more than one class.

What is an abstract class?

An abstract class cannot be instantiated and may contain abstract methods which must be implemented by subclasses.

What is an interface?

An interface defines a contract with methods that a class must implement, but does not provide method bodies.

Fragen in diesem Lernset(14)

1. What does the 'extends' keyword indicate?

A.Inheritance
B.Interface
C.Method Overloading
D.Constructor

2. Which of the following is true about method overriding?

A.It changes the method name
B.It requires a different parameter list
C.It occurs in subclasses
D.It creates a new class

3. What will happen if a subclass does not call the superclass constructor?

A.An error will occur
B.The superclass constructor will not run
C.Default constructor is called
D.Nothing will happen

4. Which type of inheritance is not supported in Java?

A.Single inheritance
B.Multiple inheritance
C.Multi-level inheritance
D.Hierarchical inheritance

5. What is the purpose of an abstract class?

A.To create objects
B.To define methods without implementation
C.To provide default behavior
D.To enable multiple inheritance

6. Which of the following allows for method overloading?

A.Same method name, different parameters
B.Same method name, same parameters
C.Different method names
D.Different return types only

7. Which of these represents a subclass?

A.class A {}
B.class B extends A {}
C.class C implements A {}
D.class D {}

8. What is the key aspect of polymorphism?

A.Single method implementation
B.Method access restriction
C.Method behavior based on object type
D.Static types only

9. What happens if a method is not overridden in a subclass?

A.Superclass method is executed
B.Subclass method is executed
C.Error occurs
D.Subclass does not compile

10. What is the primary purpose of interfaces?

A.To provide default values
B.To ensure method implementation
C.To declare fields
D.To inherit methods

11. In which of the following can you implement multiple inheritance in Java?

A.Classes
B.Interfaces
C.Abstract Classes
D.All of the above

12. Which statement is false about constructors in subclasses?

A.They can call superclass constructors
B.They cannot have parameters
C.They must not have a return type
D.They initialize object attributes

13. What does it mean if a class is marked as final?

A.It can be inherited
B.It cannot be instantiated
C.It cannot be subclassed
D.It has no methods

14. Which of the following keywords is used to call the superclass constructor?

A.super()
B.this()
C.extends
D.inherits

Ähnliche Lernsets

Eigenes Lernset erstellen

Lade ein PDF hoch, füge Notizen ein oder beschreibe ein Thema – KI erstellt Karteikarten, Quizze und mehr in Sekunden.