Java Object Oriented thinking

Source: Internet
Author: User

Describe a thing ————— object

Use a thing ————— object

In Java, a class has a description of himself (that is, a property) and the functionality (i.e., methods) that he can implement.

Appearance (attribute) + behavior (method) = specific Thing (object)

To do what you need to do by calling the object

Classes that store information

Classes that implement functionality

Interface: keyword interface A class that is connected to an interface must implement a method in an interface

Inheritance: The extends subclass inherits the parent class, the subclass can use everything that is not encapsulated in the parent class, and the parent class can also use the subclass's stuff (casts must be cast).

1  Public classASAS {2      Public Static voidMain (string[] args) {3AA a=NewAA ();4A.print ();//invokes the method of the parent class through new-out parent class object. A is the AA type of the parent class (the parent class uses the parent class method)5AA b=NewBB ();6(BB) b). print ();//The method of the subclass is called by the child class object that is out of new. B is the AA type of the parent class (the parent class uses the subclass method)7BB zi=NewBB ();8Zi.print ();//The method of the subclass is called by the child class object that is out of new. Zi is a sub-class BB type (subclass using subclass method)9     }Ten } One  A classaa{ -     voidprint () { -System.out.println ("Method of the parent class"); the     } - } - classBbextendsaa{ -     voidprint () { +System.out.println ("Methods of subclasses"); -     } +}

Java Object Oriented thinking

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: 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.