Java Object-Oriented understanding

Source: Internet
Author: User

Objective:

Before writing a blog, we should have a good positioning, can be a sort of knowledge and understanding, can be a new technology, can be difficult to analyze and understand the difficulties.

Body:

  Java Object-oriented understanding. The popular point to say is that the object is a matter of practical significance (everything objects) is actually a parameter in Java, but this parameter actually represents something (such as you have a class tourism, this class on the property name, age. When tourism tou = new Tourism (), this tou parameter actually represents a meaningful object for a class tourism, and a method tourism (tourism tou) then this tourism method can be regarded as tourism can tourism behavior), invisible, but actually exists.

generally speaking, object-oriented is the characteristic of an object (attribute: Tourism (the name, age) and behavior (method: Tourism Method a series of operations (methods are functions in C that are called methods in Java from a language's function).

Let's look at an example so we can better understand object-oriented:

/*** Fares for tourist attraction tickets*/ Public classtourism{/*Visitor Attributes (features)*/         PublicString name;//name     Public intAge//Age            /*Method (behavior) ticket purchase*/     Public voidTourism () {if(age>=18) {System.out.println (name+ "The Age is:" +age+ ", the ticket price is: 20 Yuan"); }Else if(Age<18 && age>10) {System.out.println (name+ "The Age is:" +age+ ", the ticket price is: 10 Yuan"); }Else if(Age>0 && age<=10) {System.out.println (name+ "The Age is:" +age+ ", Ticket free"); }    }}ImportJava.util.Scanner; Public classtouri{ Public Static voidMain (string[] args) {Scanner input=NewScanner (system.in);/*Tourism tou = new Tourism (); The actual object (the actual thing) of the ticket price that the tourist buys.*/Tourism Tou=NewTourism ();  while(true) {System.out.println ("Please enter your name:"); Tou.name=Input.next (); if("N". Equals (Tou.name)) {System.out.println ("Exit program");  Break; } System.out.println ("Please enter your Age:"); Tou.age=Input.nextint ();        Tou.tourism (); }    }}

The first time to write a blog, there is something wrong or bad place, I hope you can point. If you can, please give your valuable comments, thank you!!!

Java Object-Oriented understanding

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.