Dark Horse Programmer Entry Blog ...
Java Object-oriented language
object: The only real thing that exists.
For example: My family's dog,
class: actual is the common attribute and behavior of a certain type of thing extraction. Abstract concept ... For example, do you know what car I'm worth?
We have been exposed to a lot of objects since we were young, and our brains classify things that have the same attributes and behaviors.
If you don't understand it, look:
The following objects have the basic properties of the class (wheel, exhaust pipe, color). Can be said to be on the bus. Class is like the drawing of a Zhang Ji car, an abstract concept.
In real life there are objects and classes of these two things. The computer is the waiter human, in order to let the computer closer to our life, this time there is an object-oriented computer language.
Process-oriented representation (C language)--------> focus on process
Object-oriented code (Java language)--------> Focus on the object, find the right object to do the right thing
Here's a picture to explain the process-oriented and object-oriented differences:
In real life: Objects---------------------> Classes
In Java: Class---------------------------> Objects
The core idea of object-oriented computer language: Find the right object to do the right thing.
How to find the right object:
1.sun has defined a lot of classes, we just need to know these classes, we can create objects using these classes.
2. Custom classes, using custom classes to create objects.
Beginners should learn the custom classes first to learn grammar and keywords so that the time to read the understanding of sun-written classes.
The custom class creates the object'sthree-step:
1. Customize the class.
Format:
Class Name {
The public properties of a thing are described using member variables.
The public behavior of a thing uses a function description.
}
2. Create an object from a custom class.
Format:
Class Name Variable name = new class name ();
3. Access (set) the properties of the object or invoke the function of the object.
1. Access the format of the object properties:
Object. Property name.
2. Set the properties of the object:
Object. property name = data.
3. Function of the calling object
Object. function name ();
Requirements: Use Java to describe a car class, the car has the number of wheels, name, color three properties, but also the function of running behavior.
Class car{//the public properties of a thing are described using member variables. Stringname; The attribute of the name Stringcolor; Color attribute int wheel;//number of wheels//common behavior of things use function description. public void Run () {System.out.println (name+) "Fast Running ..."}} Class Demo1 {public static void main (string[] args) {//uses the car class to declare a C variable, and the C variable points to a car object. Car c = new car (); Sets the property value of the car object. C.name = "BMW"; c.color = "white"; C.wheel = 4;//The property value of the vehicle object System.out.println ("Name:" + c.name+ "color:" + c.color+ "number of Wheels:" +c.wheel); c . Run ();}}
Results:
Name: BMW color: White Wheel Number: 4
BMW is running fast.
If there is no assignment for the car below the variable all output initialization value: First name: null color: null number of wheels: 0
The following is a reference to the initialization values of the base data type:
Boolean value: Boolean default False
Character: Char,
Integer: Byte,short,int,long is 0
Real number: Float,double is 0.0 of type double
Object reference is null
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Definition of Java_se base--23. class