Learn to practice Java Object-oriented trapezoid area

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.