Knowledge of Java polymorphism, interfaces, abstract classes

Source: Internet
Author: User

1,

Polymorphic: A reference to a parent class that points to a subclass object, has inheritance, has overrides

Polymorphic expression: Cat is a Animal

Rule: polymorphic objects cannot call methods that are not in the parent class

Definition: Animal cat = new Cat ();

2,

Interface: The class implements the interface implement, is also a kind of extremely abstract abstract class, also is the class many behavior collection

The interface expresses: cat has the capacity to jump

Rule: member non-static method is automatically public, can not have method body, can have return value, can have parameter

Member properties are 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 Interface public class Dool implements doolfun{

@Override
void Open () {
TODO auto-generated Method Stub
System.out.println ("Open box");
}

}

3,

Abstract classes: Classes can inherit abstract class extends, which is the set of behaviors that a class unifies, and abstract classes are just a few special classes.

Abstract class expresses: cat has eat behavior

Rule: A member method can have a method body and can contain non-abstract methods, but the abstract method and the method in the interface must be implemented in a subclass, with no method body

Abstract classes can implement polymorphic

Abstract members are automatically public

Definition: 1) abstract class animals{}

2) Inherit public class Dog extends Animals

Knowledge of Java polymorphism, interfaces, abstract classes

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: info-contact@alibabacloud.com 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.