Docsity

Java Concepts Chapter 13: Inheritance - Exercises and Questions, Exams of Computer Programming

Toggle sidebar
bg1
Java Concepts Chapter 13: Inheritance
Questions
a class which you can create objects for ✓concrete class
a subclass has no access to ✓private fields of its superclass
a type with a finite number of values ✓enumerated type (enum)
all methods of classes in the same package can access the feature
✓package access
Any new instance fields that you define in the subclass are present only in
✓subclass objects
calling a superclass constructor ✓use the super keyword in the first
statement of the subclass constructor
super(initialBalance)
can be accessed by methods of all classes ✓public features
can be converted into superclass references ✓subclass references
can only be accessed by the methods of their own class ✓private features
class for which you cannot create obects ✓abstract class
define the toString method to ✓yield a string that describes the object
state
pf3
pf4

Partial preview of the text

Download Java Concepts Chapter 13: Inheritance - Exercises and Questions and more Exams Computer Programming in PDF only on Docsity!

Java Concepts Chapter 13: Inheritance

Questions

a class which you can create objects for ✓concrete class a subclass has no access to ✓private fields of its superclass a type with a finite number of values ✓enumerated type (enum) all methods of classes in the same package can access the feature ✓package access Any new instance fields that you define in the subclass are present only in ✓subclass objects calling a superclass constructor ✓use the super keyword in the first statement of the subclass constructor super(initialBalance) can be accessed by methods of all classes ✓public features can be converted into superclass references ✓subclass references can only be accessed by the methods of their own class ✓private features class for which you cannot create obects ✓abstract class define the toString method to ✓yield a string that describes the object state

Denotes inheritance ✓solid line with hollow triangle tip failing to invoke the superclass method results in ✓infinite recursion four levels of controlling access to fields ✓public access, private access, protected access, package access how do abstract classes differ from interfaces ✓abstract classes can have instance fields and they can have concrete methods and constructors how to wrtie equals method ✓cast the otherObject parameter to the type of your class, and then compare the fields of the implicit parameter and the other parameter If you define a method that does not exist in the superclass then, ✓the new method can only be applied to subclass obects If you want your toString method to be usable by a subclass ✓return getClass().getName() + desired print info in enumeration classes, the clone method returns ✓the given object WITHOUT making a copy in enumeration classes, the toString method returns ✓a string that equals the objects name In Java, every class that does not specifically extend another class extends this ✓the class Obect

protected features can be accessed by ✓all subclasses and all classes in the same package sets of classes can form complex ✓inheritance hierarchies Subclasses inherit all ✓fields from the superclass testing whether two objects belong to the same class ✓if (otherObject == null) return false; if (getClass() != otherObject.getClass()) return false; tests whether two objects have the same contents ✓equals method tests whether two references are to the same object ✓== method the default access when no access modifier is given ✓package access The subclass inherits these from the superclass ✓behavior and state things you can do to methods in a subclass ✓override, inherit, define new use this keyword to call a method of the superclass ✓super ex. super.deposit(amount); when you call the clone method you must use a ✓cast ex. BankAccount clonedAccount = (BankAccount) account.clone(); You can never override ✓instance fields