Presentation is loading. Please wait.

Presentation is loading. Please wait.

Class vs Abstract vs Interface

Similar presentations


Presentation on theme: "Class vs Abstract vs Interface"— Presentation transcript:

1 Class vs Abstract vs Interface

2 Class 100% concrete (full defined) data type
All methods are fully implemented May be directly instantiated (created) but invoking one of its constructors

3

4 extends Parent – Child Classes
A class (fully functioning) may have sub-classes. The subclass inherits functionality from the parent

5 Student is the parent class
HighSchoolStudent is-A student HighSchoolStudent inherits from Student Notice that HighSchoolStudent does NOT have a name field or methods related to name. These things are inherited and therefore you do not repeat them in the child class. Is-A

6 c.getName() will work because HighSchoolStudent inherited that method from Student

7 b is a reference to a Student object – when you output b it looks to see what type of Student is it actually referencing and calls the toString of the HighSchoolStudent class.

8 Abstract Incomplete class definition (conceptual)
May include fully implemented methods May include unimplemented abstract methods Cannot be directly instantiated Subclasses of an abstract class must: Implement all the abstract methods Or Be declared as abstract also

9 This class is abstract because there is not a default area or perimeter formula

10 Both Square and Circle inherit name from the Shape class.
Both Square and Circle implement getArea() and getPerimeter() with the correct formula.

11 The output is calling the toString for each object
The output is calling the toString for each object. In the toString the getArea() and getPerimeter() methods are called. Java uses dynamic binding to call the correct getArea() method – meaning if it is a Circle Java will call Circle’s getArea() and if it is a Square Java will call Square’s getArea()

12 You cannot instantiate a Shape because it is abstract
s.getArea() would not work because getArea is abstract in the Shape class.

13 Interface 100% abstract (conceptual) data type
Declares what operations (functionality) the type will have Doesn’t define any operations (no implemented methods) Only abstract methods Cannot be directly instantiated (NO CONSTRUCTOR)


Download ppt "Class vs Abstract vs Interface"

Similar presentations


Ads by Google