Java Object-oriented

Source: Internet
Author: User

Process-oriented vs . Process -oriented

Process oriented: 1 DIY->2 buy vegetables->3 wash vegetables->4 cooking rice stir->5 difficult to eat, wasting time

Object-oriented: 1 Find a Professional object->2 restaurant. Order->3 Restaurant, cook->4 Rice Delicious, save time

Object-oriented thinking first to find objects, directly to use, such as Sun did not provide, then build their own objects

Second, object-oriented features

1) package (encapsulation)

2) Inheritance (inheritance)

3) polymorphism (polymorphism)

The process of development: in fact, is constantly creating objects, using objects, directing objects to do things

The process of design: In fact, the relationship between managing and maintaining objects


Third, Java describes things

Properties: member variables in a class

Behavior: member functions in a class


Iv. Defining classes

1) define class using class keyword

2) The class name is the identifier, the naming rule, the first letter of the word capital, the first letter of multiple words capitalized

3) The class name immediately follows a pair of {} to indicate the start and end of the class

4) No initialization values required

public class Car {String color;//member variable int num;//member variable//member function void Run () {System.out.println (color + "car, number of tires:       "+ num +" One, run up "); }}

V. Creating objects

Class Cardemo {public static void main (string[] args) {//uses the New keyword to open up space in the heap memory, creating an entity//to facilitate the use of production vehicles, named              C is the car type, called class type variable//C is a reference to hold, the new production of the car is not directly assigned to C, just like the TV remote control car c = new car ();  C.run (); Use object's Function}}



Vi. invocation of Object members

1) member variables

2) Member method

public class Cardemo {public static void main (string[] args) {car c = new Car ();        The object name. The member variable name returns the numeric value stored in the member variable int num=c.num;               SYSTEM.OUT.PRINTLN (num);        The name of the object, the name of the member variable, or the value of the member variable c.num = 4;               C.color = "BLACK";        The name of the object. Member method ();    C.run (); }}

Example

[email protected] java]# cat cardemo.javaclass Car {String color;    int num;   void Run () {System.out.println (color + "colour of the car, number of tires:" +num + "one, run up");        }} class Cardemo {public static void main (string[] args) {car c = new Car ();        C.color = "Red";        C.num = 4;    C.run (); }}//Run results [[email protected] java]# java cardemored color car, number of tires: 4, run up.


Java Object-oriented

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.