Unit 5 - Inheritance Flashcards

Study Goals: - for what purpose inheritance is used in object-oriented systems - how inheritance is expressed in UML class diagrams - the difference between a superclass and a subclass - how inheritance between Java classes is expressed - what is meant by overriding inherited attributes and methods

1
Q

What is a “is a” relationship?

A
  • important concept in object orientation and is classified as an inheritance relationship
  • relationship expresses that a class A can be viewed as similar to a different class B
  • it expresses that a class is a special type of another class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a superclass?

A
  • also called: “base class” or “derived class”
  • is the designation for a class from which other classes are derived
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a subclass?

A
  • more specific type of superclass
  • have all the attributers of the superclass, but also define other attributes that are important for their own description
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is inheritance?

A
  • it is what allows information to be conveyed about things either generally or specifically while avoiding redundancy
  • helps reduce repetition in design
  • methods and associations of the superclass are shared
  • not only form of the superclass, but also its behavior and its use its inherited
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How are Inheritances implemented in Java?

A
  • implemented using Extension
  • public class Book extends Product {}
  • the inherited attributes and methods can be used like normal instance attributes and methods
  • the inherited attributes receive the values from the superclass
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is assignment compatiblity?

A
  • variable of the type of a superclass can also be assigned sublass objects
  • reversed its not possible
  • the type of a variable decides which attributes and methods can be invoked
  • used to ensure the loosest possible coupling of individual classses in large software systems
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is overriding?

A
  • process of implementing an inherited method
  • methods can be overridden in sublasses by creating a method with the same signature and implementating a new method body
  • if an instance of the sublass is generated and inherited attributes or methods are accessed, then the overridden versions are selected
  • Java keyword: super allows superclass to be addressed and its attributes and methods can be accessed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly