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