日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java中抽象类继承抽象类_Java中的抽象类用示例解释

發布時間:2023/11/29 java 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java中抽象类继承抽象类_Java中的抽象类用示例解释 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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類的功能來創建Car或Motorcycle :

abstract class Vehicle {//variable that is used to declare the no. of wheels in a vehicleprivate int wheels;//Variable to define the type of motor usedprivate Motor motor;//an abstract method that only declares, but does not define the start //functionality because each vehicle uses a different starting mechanismabstract 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 ,而是可以使用之前聲明的Car和Motorcycle類并創建這些實例:

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

更多信息: (More information:)

  • Learn Functional Programming in Java - Full Course

    學習Java函數式編程-完整課程

  • Getters and Setters in Java Explained

    Java中的Getter和Setters解釋了

  • Inheritance in Java Explained

    Java繼承說明

翻譯自: https://www.freecodecamp.org/news/abstract-classes-in-java-explained-with-examples/

java中抽象類繼承抽象類

總結

以上是生活随笔為你收集整理的java中抽象类继承抽象类_Java中的抽象类用示例解释的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。