Java polymorphism, interface, abstract class awareness, java Polymorphism

Source: Internet
Author: User

Java polymorphism, interface, abstract class awareness, java Polymorphism


Polymorphism: the reference of the parent class points to the subclass object, which has inheritance and rewriting.

Polymorphism: cat is an Animal

Rule: a multi-state object cannot call methods that are not in the parent class.

Definition: Animal cat = new Cat ();


Interface: the class implementation interface implement is also an extremely abstract class and a set of many behaviors of the class.

The interface indicates that cat has the jump Behavior capability.

Rule: the non-static method of a member is automatically public. The method body is not allowed, the return value is allowed, and the parameter is allowed.

The member property is automatically public final static

Methods In the interface must be implemented

Definition: 1) interface public interface DoolFun {

Public static float pi = 3.45f;
Void alert ();


2) Implement the interface public class dool implements DoolFun {

@ Override
Void open (){
// TODO Auto-generated method stub
System. out. println ("open box ");



Abstract class: the class can inherit the abstract class extends, which is a collection of behaviors of the class. The abstract class is just a few special classes.

Abstract classes Express: cat has eat Behavior

Rule: A member method can have a method body and can contain non-Abstract METHODS. abstract methods are the same as methods in interfaces and must be implemented in subclasses without a method body.

Abstract classes can achieve Polymorphism

The abstract member is automatically public.

Definition: 1) abstract class Animals {}

2) inherit from public class Dog extends Animals

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.