`
TracyKelvin
  • 浏览: 22637 次
  • 性别: Icon_minigender_1
  • 来自: 广州
最近访客 更多访客>>
社区版块
存档分类
最新评论

Learning the Java Language(1.3)

    博客分类:
  • Java
阅读更多

What Is Inheritance?

 

Different kinds of objects often have a certain amount in common with each other. Mountain bikes, road bikes, and tandem bikes, for example, all share the characteristics of bicycles (current speed, current pedal cadence, current gear). Yet each also defines additional features that make them different: tandem bicycles have two seats and two sets of handlebars; road bikes have drop handlebars; some mountain bikes have an additional chain ring, giving them a lower gear ratio.

Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. In this example, Bicycle now becomes the superclass of MountainBike, RoadBike, and TandemBike. In the Java programming language, each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses:

A hierarchy of bicycle classes.

The syntax for creating a subclass is simple. At the beginning of your class declaration, use the extends keyword, followed by the name of the class to inherit from:

class MountainBike extends Bicycle {

     // new fields and methods defining a mountain bike would go here

}

This gives MountainBike all the same fields and methods as Bicycle, yet allows its code to focus exclusively on the features that make it unique. This makes code for your subclasses easy to read. However, you must take care to properly document the state and behavior that each superclass defines, since that code will not appear in the source file of each subclass.

分享到:
评论

相关推荐

    Machine Learning in Java epub

    Machine Learning in Java 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    Deep Learning: Practical Neural Networks with Java 完整高清英文azw3版

    This course aims to create a smooth learning path that will teach you how to effectively use deep learning with Java with other de facto components to get the most out of it. Through this ...

    Deep Learning in Natural Language Processing 无水印原版pdf

    Deep Learning in Natural Language Processing 英文无水印原版pdf pdf所有页面使用FoxitReader、PDF-XChangeViewer、SumatraPDF和Firefox测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 ...

    Packt.Publishing.Learning.jQuery.1.3

    ### 关于《Learning jQuery 1.3》的知识点解析 #### 一、书籍基本信息与版权说明 - **书籍名称**:《Learning jQuery 1.3》 - **出版方**:Packt Publishing - **作者**:Jonathan Chaffer 和 Karl Swedberg - **...

    Learning.Java.by.Building.Android.Games

    So, you should first obtain a solid grasp of the Java language and its foundation APIs to improve the chances of succeeding as an Android app developer. This book will show you how to get your ...

    [jQuery基础教程.(英文原版)].Packt.Publishing.Learning.jQuery.1.3

    《Learning jQuery 1.3》是一本由Packt Publishing出版的专业指南,旨在帮助开发者掌握jQuery这一流行的JavaScript库。本书由Jonathan Chaffer和Karl Swedberg共同编写,通过简单易懂的方式介绍了如何利用jQuery来...

    Deep Learning in Natural Language Processing

    In particular, the striking success of deep learning in a wide variety of natural language processing (NLP) applications has served as a benchmark for the advances in one of the most important tasks ...

    The Psychological Course of Java Language Learning.zip

    总的来说,"The Psychological Course of Java Language Learning.zip"可能是一个综合性的资源,旨在帮助学习者理解并克服在学习Java过程中可能出现的心理障碍,提供科学的学习策略,结合实践项目,以及提倡社区参与...

    Machine Learning in Java.PDF+代码

    Machine Learning in Java.PDF文档+代码 If you want to learn how to use Java's machine learning libraries to gain insight from your data, this book is for you. You should be familiar with Java ...

    Learning Java by Building Android Games

    It uses the most popular programming language, Java, as the primary language for building apps of all types. However, this book is unlike other Android books in that it doesn’t assume that you ...

    Learning Modular Java Programming.pdf

    《Learning Modular Java Programming》是一本介绍使用Java和Spring框架进行模块化编程构建应用的图书。模块化编程是一种编程范式,它鼓励将一个大型的应用程序分解成更小、更易管理的部分,即模块。在Java中,模块...

    Deep Learning for Natural Language Processing--2018

    Gain the fundamentals of deep learning and its mathematical prerequisites Discover deep learning frameworks in Python Develop a chatbot Implement a research paper on sentiment classification

    Machine Learning in Java azw3

    Machine Learning in Java 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

Global site tag (gtag.js) - Google Analytics