课程: Java 8+ Essential Training: Objects and APIs
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Extend classes and override methods - Java教程
课程: Java 8+ Essential Training: Objects and APIs
Extend classes and override methods
- [Narrator] In Java, you create a subclass of an existing class with the key word extends. Each class in Java can have one and only one super class. If you don't define an explicit super class then your custom class extends the Java object class. I'm going to start by creating a new custom class. It's going to hold some data. And in Java, there's a convention that says, this kind of class is sometimes known as a model class. I'll organize my code by putting these kinds of classes in their own package. From the base package of the application, I'll create a new package, and I'll name it model. And then I'll create a new Java class that's in that package. And I'll name it ClothingItem. This is going to become a super class. I'm creating an inheritance hierarchy, where I have a clothing item class, and then it can have one or more sub-classes for each type of clothing I want to sell. All clothing items have a certain amount of common functionality. Each item has a particular type, each…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。