Inheritance Flashcards
1) Definition - Inheritance
Object-oriented programming languages provide the ability to e_______ existing classes by adding attributes and
methods to them. Not directly, though!
We create a subclass that inherits all of the features of the base-class, we can then add whatever we like to the sub-class.
This is called inheritance.
extend
2) How to link a sub-class to a base-class?
We use the keyword _____________ in the header of the sub-class to link them.
e.g.
public class PartTimeEmployee extends Employee // this class is a subclass of Employee
extends
3) .toString
A toString() is an in-built method in Java that returns the value given to it in string format. Hence, any object that this method is applied on, will then be returned as a string object.
4) Java Annotation.
Annotations begin with the @ symbol, and always start with an u_____ case letter.
e.g. @Override
Although it is not mandatory that we include this annotation, it is very good practice to do so. Its purpose is to inform the compiler that we are overriding a method from the superclass.
upper
5) Important Note
You can call a super class m_______ from within a sub class method.
BUT you CAN’T call a sub class method from within a super class method.
The conversion of a superclass type into subclass type is called SPECIALIZATION in java.
Specialization means going down from a more general form to a more s______ form. Thus, its s______ will be narrowed. Hence, this conversion is also called narrowing or down-casting in referenced data types.
method
specific
scope
6) Method Overriding
In the case of method overriding in subclasses, the methods have the same parameter list but belong to different c_______
—the superclass and the subclass.
In this case, they are distinguished by the o__________ with which they are associated.
Basically, using the same methods for different objects!
See chp. 9, pp 249-250
classes
object
7) The ‘final’ modifier
The ‘final’ modifier can also be used to modify a class.
This means that the class cannot be s__________.
The ‘final’ modifier can also modify a method.
This means that the method cannot be o___________.
subclassed
overridden
8) Inheriting from Object Class
Every new class that you define automatically inherits from the Object class.
The Object class defines ___ methods, therefore each subclass of Object inherits these methods.
These 11 methods can be called on objects of any class.
11
9) Abstract Classes
An abstract class is simply a class that you CANNOT create objects from, or in more technical terms, i___________
object from.
For example, a base class that is far too general. It would be better to make objects from sub classes that are more detailed.
instantiate
10)
To make a class an ‘abstract’ class simply put the word ‘abstract in the class h___________
e.g. public abstract class Cat {
}
header
11) Abstract Methods
In any absract classes, you can make abstract methods.
When you make a method abstract, you don’t specify a b_____ for the method. You just declare it and end it with a
s_______________
e.g.
public abstract class Animal {
int age;
String name;
public abstract void makeNoise( ) ;
}
body
semi-colon
12) Why would you make a method abstract, in an abstract class?
Just like the super class is very general, a method in that class could also be too general. E.g. An animal class with a method called ‘makeNoise’. It would be something non-specific like, “Hello, I am an animal”.
This might not be useful in sub classes where we could specifiy the noise an individual animal might make.
Why not just remove the method from the super class?
Because we want that method to be a part of every sub class. We want our animals to make a noise and this forces each and every subclass to include the method.
13) Wrapper Classes
For every p_____________ data type we have wrapper classes’
primitive
14)
The name of the wrapper class is similar to the basic type, but begins with a c_______ letter
—for example Integer,Character, Float, Double.
They are called wrappers because they “wrap” aclass around the basic type.
capital
15) What are wrapper classes?
A wrapper class provides a way to use primitive date types as reference types.
a String is an example of a r__________ data type.
Refrence data types cointain useful m________.
Reference data types can be used in certain collections, e.g. ArrayList
reference
methods