Docsity

Inheritance and Polymorphism in Java, Exams of Nursing

Toggle sidebar
bg1
AP Computer Science A - Review 1 2024
Inheritance defines a relationship between _______ that share characteristics -
objects
Inheritance is when a new class (_______) is created from an existing class
(_______) - subclass, superclass
The subclass _______ characteristics of its superclass - inherits
When methods of superclasses are overwritten by subclasses - Method overriding
If part of the original method implementation from the superclass is retained, the
rewrite is referred to as _______ - Partial overriding
To specify the inheritance relationship between a subclass and a superclass, in the
declaration of the subclass, use the keyword _______ - extends
ex: public class Subclass _______ Superclass {} - extends
Are private instance variables of a superclass directly accessible to its subclasses? -
No
pf3
pf4
pf5

Partial preview of the text

Download Inheritance and Polymorphism in Java and more Exams Nursing in PDF only on Docsity!

Inheritance defines a relationship between _______ that share characteristics - objects Inheritance is when a new class (_______) is created from an existing class (_______) - subclass, superclass The subclass _______ characteristics of its superclass - inherits When methods of superclasses are overwritten by subclasses - Method overriding If part of the original method implementation from the superclass is retained, the rewrite is referred to as _______ - Partial overriding To specify the inheritance relationship between a subclass and a superclass, in the declaration of the subclass, use the keyword _______ - extends ex: public class Subclass _______ Superclass {} - extends Are private instance variables of a superclass directly accessible to its subclasses? - No

Can subclasses directly invoke the public accessor and mutator methods of the superclass? - Yes A method in a superclass is overriden in a subclass by defining a method with same _______ - return type and signature (name and parameter types) _______ are never inherited - Constructors A superclass must have a default, zero-parameter _______ - Constructor A subclass constructor can be implemented with a call to the _______ - super method (super();) If super is used in the implementation of a subclass constructor, it must be used in the _______ of the constructor body - first line If no constructor is provided in the subclass, it calls the default constructor of the _______ - superclass

Casting a superclass to a subclass type is called _______ - Downcasting A run-time exception thrown to signal an attempt to cast an object to a class of which it is not an instance - ClassCastException A superclass that represents an abstract concept, and therefore should not be instantiated - Abstract class An abstract class creates no _______ - objects Abstract methods have no _______, because every subclass will need to override the method (so no point) - implementation Abstract methods must be declared in an _______ - abstract class An abstract class is declared with the keyword abstract in the _______ - header The keyword _______ is still used to declare the subclass - extends

If a subclass of an abstract class does not provide implementation code for all the abstract methods of its superclass, it too becomes an _______ - abstract class It is possible for an abstract class to have no _______ methods - abstract Does an abstract class need constructors? - No Does polymorphism work with abstract classes? - Yes A collection of related methods whose headers are provided without implementation - Interface All of the methods in an interface are both _______ (no need to explicitly include these keywords, however) - public and abstract Interfacces provide a _______ for behavior of any class - framework If a class fails to provide implementations for all the methods declared in an interface, it must be declared _______ - abstract

Subclasses of a superclass with Comparable and compareTo will automatically _______ Comparable and inherit the compareTo method. - implement