Java 基础 polymorphism(多态)

本文探讨了Java中的多态性,包括类的继承、抽象类和方法、实例化过程。强调了抽象类不能直接实例化,子类必须实现抽象方法才能成为具体类。还介绍了`instanceof`运算符用于确定对象的实际类型,并展示了如何根据对象类型进行向下转型。另外,提到了`final`关键字在方法和类中的使用,表明`final`方法不可重写,`final`类不能被继承。
摘要由CSDN通过智能技术生成

多态: 当存在多个类依次继承(呈瀑布型继承),当在主函数中实例化最底层(辈份最小)的类时,构造函数的调用顺序是从最高辈分的类到最底层类。

----A superclass references refers to a subclass object. (note the opposite is a syntax error.)

e.g:

Animal [0] = new Dog();// Animal[0] is super reference, and the Dog() is the new object.


----Which subclass’s method to invoke is decided at the execution time. In detail, it depends on the data type of the object.

Abstract Classes and Methods


1. An abstract method is declared using keyword abstract.

2.Once a class has at least one abstract method, it must be declared as abstract class.

3.Important: abstract classes cannot be used to instantiate objects, because they are incomplete.

4.If a superclass is an abstract class, its subclasses must implement all the abstract methods in orde

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值