博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java中抽象类继承抽象类_Java中的抽象类用示例解释
阅读量:2518 次
发布时间:2019-05-11

本文共 1861 字,大约阅读时间需要 6 分钟。

java中抽象类继承抽象类

Abstract classes are classes declared with abstract. They can be subclassed or extended, but cannot be instantiated. You can think of them as a class version of interfaces, or as an interface with actual code attached to the methods.

抽象类是用abstract声明的类。 它们可以被子类化或扩展,但是不能被实例化。 您可以将它们视为接口的类版本 ,或与方法附带实际代码的接口。

For example, say you have a class Vehicle which defines the basic functionality (methods) and components (object variables) that vehicles have in common.

例如,假设您有一个Vehicle类,它定义了Vehicle共有的基本功能(方法)和组件(对象变量)。

You cannot create an object of Vehicle because a vehicle is itself an abstract, general concept. Vehicles have wheels and motors, but the number of wheels and the size of motors can differ greatly.

您无法创建Vehicle对象,因为Vehicle本身就是一个抽象的通用概念。 车辆具有车轮和电动机,但是车轮的数量和电动机的尺寸可能相差很大。

You can, however, extend the functionality of the vehicle class to create a Car or a Motorcycle:

但是,您可以扩展Vehicle类的功能来创建CarMotorcycle

abstract class Vehicle{  //variable that is used to declare the no. of wheels in a vehicle  private int wheels;    //Variable to define the type of motor used  private Motor motor;    //an abstract method that only declares, but does not define the start   //functionality because each vehicle uses a different starting mechanism  abstract void start();}public class Car extends Vehicle{  ...}public class Motorcycle extends Vehicle{  ...}

Remember, you cannot instantiate a Vehicle anywhere in your program – instead, you can use the Car and Motorcycle classes you declared earlier and create instances of those:

请记住,您不能在程序中的任何地方实例化Vehicle ,而是可以使用之前声明的CarMotorcycle类并创建这些实例:

Vehicle newVehicle = new Vehicle();    // InvalidVehicle car = new Car();  // validVehicle mBike = new Motorcycle();  // validCar carObj = new Car();  // validMotorcycle mBikeObj = new Motorcycle();  // valid

更多信息: (More information:)

翻译自:

java中抽象类继承抽象类

转载地址:http://zmrwd.baihongyu.com/

你可能感兴趣的文章
chromium浏览器开发系列第三篇:chromium源码目录结构
查看>>
java开发操作系统内核:由实模式进入保护模式之32位寻址
查看>>
第五讲:单例模式
查看>>
Python编程语言的起源
查看>>
Azure ARMTemplate模板,VM扩展命令
查看>>
(转)arguments.callee移除AS3匿名函数的侦听
查看>>
onNewIntent调用时机
查看>>
MYSQL GTID使用运维介绍(转)
查看>>
04代理,迭代器
查看>>
解决Nginx+PHP-FPM出现502(Bad Gateway)错误问题
查看>>
Java 虚拟机:互斥同步、锁优化及synchronized和volatile
查看>>
2.python的基本数据类型
查看>>
python学习笔记-day10-01-【 类的扩展: 重写父类,新式类与经典的区别】
查看>>
查看端口被占用情况
查看>>
浅谈css(块级元素、行级元素、盒子模型)
查看>>
Ubuntu菜鸟入门(五)—— 一些编程相关工具
查看>>
PHP开源搜索引擎
查看>>
12-FileZilla-响应:550 Permission denied
查看>>
ASP.NET MVC 3 扩展生成 HTML 的 Input 元素
查看>>
LeetCode 234. Palindrome Linked List
查看>>