1 Public classSquare {2 intChang;3 intKuan;4 intMianji;5 String colour;6 //constructor Method One parameter7Square (intCintk) {8chang=C;9kuan=K;Ten } One Square (String se) { AColour=se; - } - //construction Method Two no parameter default is None the Square () { - - } - + //No return value no parameter - /*void Juxing () { + Mianji=chang*kuan; A }*/ at - //two no return values have parameters - /*void juxing (int chang,int Kuan) { - Mianji=chang*kuan; - - }*/ in - //three have return values without parameters to intjuxing () { +mianji=chang*Kuan; - returnMianji; the } * //four have return values with parameters $ /*int juxing (int chang,int Kuan) {Panax Notoginseng Mianji=chang*kuan; - return Mianji; the + }*/ A the Public Static voidMain (string[] args) { + - $Square shu=NewSquare (4,3); $ -System.out.println ("rectangular area =" +shu.juxing ()); - the - WuyiSquare ss=NewSquare ("Green"); the System.out.println (); - System.out.println (ss.colour); Wu } -}
2016/1/17 Rectangular Area 1, construction method initialize length and width, 2, define member method to find rectangular area