Java Basics-Abstract classes, abstract methods

Source: Internet
Author: User

Class Shape

1 Package Com.shape;2 3  Public Abstract classShape {4     DoubleArea//5     DoublePer//6String color;//7      PublicShape () {8     }9      PublicShape (String c) {Ten          This. color=C; One     } A     Abstract  DoubleGetarea (); -     Abstract  DoubleGetper (); -     Abstract  voidShowAll (); the      Public  voidGetColor (String c) { -          This. color=C; -          -     } +      -}
class Shape

Class Rectangle

1 Package Com.shape;2 3  Public classRectangle extends shape{4     DoubleWidth;//5     DoubleHeight//6      7 @Override8     DoubleGetarea () {9         returnsuper.area=width*height;Ten     } One  A @Override -     DoubleGetper () { -         returnsuper.per=width*2+height*2; the     } -  - @Override -     voidShowAll () { +         //TODO auto-generated Method Stub -System. out. println ("??? ε???????"+getarea () +"????"+Getper ()); +     } A      PublicRectangle () {} at      PublicRectangle (DoubleWDoubleh) { -          This. Width=W; -          This. height=h; -     }  -  -}
Rectangle

Class Circle

1 Package Com.shape;2 3  Public classCircle extends shape{4     DoubleRadius//??5 6 @Override7     DoubleGetarea () {8         returnsuper.area=radius*3.14*radius;9     }Ten  One @Override A     DoubleGetper () { -         returnSuper.per=2*radius*3.14; -     } the  - @Override -     voidShowAll () { -         //TODO auto-generated Method Stub +System. out. println ("?? ε???????"+getarea () +"????"+Getper ()); -     } +      PublicCircle (DoubleR) { A          This. radius=R; at     } -     PublicCircle (String c) { -         This. color=C; -         -    } -}
Circle

Text

Package Com.shape;  Public class text {    publicstaticvoid  main (string[] args) {        Rectangle R= New Rectangle (3.0,4.0);        R.showall ();        Circle C=new Circle (5.3);        C.showall ();    }}

Java Basics-Abstract classes, abstract methods

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.