From the course: Java 8+ Essential Training: Objects and APIs
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Use abstract classes and methods - Java Tutorial
From the course: Java 8+ Essential Training: Objects and APIs
Use abstract classes and methods
- [Instructor] When designing an object-oriented contract based programming architecture, you can frequently choose between using interfaces and abstract classes. You mark an abstract class with the abstract keyword in the class declaration. When it's abstract, it can't be instantiated directly. You have to use one of its subclasses. So, in this project I'll go to clothing item dot java. And I'm going to turn clothing item into an abstract class. I'll just add the keyword abstract right here. I need to keep the class keyword as well. Now, that class can't be instantiated directly. And if I go to the main class, I see an error condition now, saying that clothing item is abstract, cannot be instantiated. I'm going to just comment out that bit of code. I'm not going to need it anymore. But notice, I can still instantiate the subclass, shirt, using the shirt classes constructor and its type. And I can still create an object that's typed as the superclass as long as I use one of the…
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.