1.
* Description: Class, equivalent to a kind, format: class name {class}, the name of the class is the same as the file name, that is, a file only one class;
* object, which is a variable of class, Format: Class name Object name (equivalent to class variable) =new class name (), for example: If int is a class, then integer variable A is an object;
* Member of the object, which treats the class as a struct, then the object is the variable of the struct, and the member of the object is the attribute in the struct.
* Process-oriented and object oriented, process-oriented problems are not used in the class, direct manipulation, object-oriented is the use of classes, the class has many properties or sub-functions, etc., and then after the definition of the object by invoking the class
* Attributes and sub-functions to solve the problem, the advantage is that the program is modular.
1 /************************************************************************************************************* ************************2 * 3 * Description: Class, equivalent to a kind, format: class name {class}, the name of the class is the same as the file name, that is, a file only one class;4 * object, which is a variable of class, Format: Class name Object name (equivalent to class variable) =new class name (), for example: If int is a class, then integer variable A is an object;5 * Member of the object, which treats the class as a struct, then the object is the variable of the struct, and the member of the object is the attribute in the struct .6 * Process-oriented and object oriented, process-oriented problems are not used in the class, direct manipulation, object-oriented is the use of classes, the class has many properties or sub-functions, etc., and then after the definition of the object by invoking the class7 * Attributes and sub-functions to solve the problem, the advantage is that the program is modular. 8 * 9 ********************************************************************************************************** **************************/Ten One Public classLiubo//Defining Classes A { - //-- The attributes of the year and the month--// - intyear=2015,month=11; the - //-- Weather Properties--// -String weather= "Sunny Day"; - + //--Displays the properties of the week with no return value--// - Public voidPrintintN//Unlike the C language, if there is no parameter in the child function can not use void, directly empty, otherwise error + { A if((n<7) && (n>0)) atSystem.out.println ("Today is week:" +n); - Else if(n==7) -System.out.println ("Today is Sunday"); - Else -SYSTEM.OUT.PRINTLN ("Error"); - } in - //-- the day after tomorrow, there is a return value--// to Public intDayaftertom (intN) + { - if((n>=1) && (n<=5)) the returnN+2; * Else if((n==6) | | (n==7)); $ returnN/7+1;Panax Notoginseng } - the //-- main function--// + Public Static voidMain (string[] args) A { theLiubo bobo=NewLiubo ();//define an object bobo, Format: Class name Object name =new object name () + -SYSTEM.OUT.PRINTLN ("This year is:" +bobo.year+ "year");//the members of the object use: Object name. Member Name $System.out.println ("Current:" +bobo.month+ "Month"); $System.out.println ("The current weather is:" +bobo.weather); -Bobo.print (5); - the if(Bobo. Dayaftertom (5) ==7)//use the return value directly when there is a return value -System.out.println ("Day After Tomorrow: Days"));Wuyi Else theSystem.out.println ("The Day After Tomorrow is the week:" +bobo. Dayaftertom (5)); - Wu - About } $ - -}
View Code
2. Java Object-oriented