


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A series of exercises and questions related to the concept of inheritance in java programming. It covers key aspects of inheritance, including subclass and superclass relationships, method overriding, access modifiers, and the use of the 'super' keyword. Designed to help students solidify their understanding of inheritance principles and practice applying them in code.
Typology: Exams
1 / 4
This page cannot be seen from the preview
Don't miss anything!



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