Presentation is loading. Please wait.

Presentation is loading. Please wait.

Inheritance Review/Recap. ClassA extends ClassB ClassA now inherits (can access and use) all public and protected elements of ClassB We can expect the.

Similar presentations


Presentation on theme: "Inheritance Review/Recap. ClassA extends ClassB ClassA now inherits (can access and use) all public and protected elements of ClassB We can expect the."— Presentation transcript:

1 Inheritance Review/Recap

2 ClassA extends ClassB ClassA now inherits (can access and use) all public and protected elements of ClassB We can expect the behavior from the subclass that the superclass had.

3 ClassA extends ClassB When the constructor from ClassA is called, it automatically calls the no- argument constructor for ClassB. If ClassB does not have a no-argument constructor, ClassA must explicitly call one of the other constructors from ClassB using the keyword super.

4 ClassA extends ClassB A subclass is the specialization of the superclass, so we can add instance variables, add methods, change parameters on methods, or change the way methods behave.

5 ClassA extends ClassB When we have a method that has the same signature in a subclass as one in the superclass, we have method overriding. Method overriding is how we change the behaviors of methods in a subclass.

6 Inheritance Looking at inheritance in reverse – if we have a lot of commonality amongst some classes, we can create one superclass to generalize amongst the subclasses. Ex) Got a lot of classes that do the same thing? Create a common superclass!

7 What’s the difference? Method overloading Method inheritance Method overriding


Download ppt "Inheritance Review/Recap. ClassA extends ClassB ClassA now inherits (can access and use) all public and protected elements of ClassB We can expect the."

Similar presentations


Ads by Google