From the course: Oracle Java Certification: 3. Methods and Inheritance
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Abstract classes and interfaces - Java Tutorial
From the course: Oracle Java Certification: 3. Methods and Inheritance
Abstract classes and interfaces
- [Instructor] Java's paradigm of object-oriented design allows us to build a hierarchy of classes. Not every class in the hierarchy needs to be fully defined. We can defer implementation to subclasses and leave some classes abstract. Abstract is a keyword denoting that a class is not completely defined, and therefore cannot be used to instantiate objects. An interface is an ultimate abstract class that has no concrete definitions except for static and default methods. We must familiarize ourselves with this type of design thinking and know the rules. Let's start with an example. This code defines a parent class at line one. It is an abstract class with an abstract method. The main class overrides this abstract method at line 12. Would this code work? What would it output? Let's try it. It turns out that this code won't compile. The error message is clear. An abstract method means a method with no definition, not…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.