1 PackageCom.hanqi;2 3 Public classLadder {4 5 DoubleShangdi;6 DoubleXiadi;7 DoubleGao;8 DoubleMianji;9 TenLadder (DoubleShangdi,DoubleXiadi,DoubleGao) One { A //using parameters to initialize properties - //This represents the current class - This. Shangdi =Shangdi; the This. Xiadi =Xiadi; - This. Gao =Gao; - - } + //method naming: verb + name; verb First letter lowercase - //void means no return value + //return value type, to be written in front of method A DoubleGetmianji () at { - //Calculate Area -Mianji = ( This. shangdi+ This. Xiadi) * This. Gao/2; - -System.out.println ("area equals" + This. Mianji); - in //Return Statement - return This. Mianji; to } + //method of main used for testing - Public Static voidMain (string[] args) the { * //Construction trapezoid $Ladder La =NewLadder (5,8,4);Panax Notoginseng - //output trapezoid Area the DoubleMJ =La.getmianji (); +System.out.println ("received return value =" +MJ); A } the + - $ $}
Learn to practice Java Object-oriented trapezoid area