Java Learning---3. Object-oriented transformation, polymorphism

Source: Internet
Author: User

1. Anminal a=new Dog ("Color"); A can only access objects that are anminal

In memory a points to a dog object.

Dog D1=dog (A);//You can see the entire dog object.

References that are defined as parent classes are most flexible.

2. Dynamic binding refers to the type of object that is referenced during execution, not during compilation.

Polymorphic bindings--late binding--instead invoke the appropriate method based on the actual type.

Three conditions for polymorphic presence: 1. Inheritance, 2. Overrides, 3. The parent class reference points to the subclass object, and new is the method of which subclass the object will call.

3.Final Keywords: Final variable values cannot be changed, methods cannot be overridden, and final classes cannot be inherited.

Equivalent to const in C + +.

4. Interface: Java only supports single inheritance, interface is a special kind of abstract class, abstract class contains only the definition of constants and methods, there is no implementation of variables and methods.

public interface runner{

public static final int id=1;

public void start ();

}

Interface attribute: The property declared in the interface defaults to public static final, which can only be an abstract method.

Class Student implements runner{

public void Start () {

SYSTEM.OUT.PRINTLN ("Student is Runner");

}

}

A class can implement multiple unrelated interfaces.

Multiple unrelated classes can implement an interface.

There is polymorphism.

Java Learning---3. Object-oriented transformation, polymorphism

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.