java学习52天2020/8/26

class Shape {
     public double getArea() {
        return 0;
     }
 }

 class Rectangle extends Shape {
     private double len;
     private double width;
     public Rectangle(double len, double width) {
        super();
        this.len = len;
        this.width = width;
    }
     public double getArea() {
         return len * width;
     }
 }

 class Circle extends Shape {
     private double r;
     public Circle(double r) {
         super();
         this.r = r;
     }
     public double getArea() {
         return 3.14 * r * r;
     }
 }

 public class Square extends Rectangle {
     public Square(double len, double width) {
         super(len, width);
     }
     public static void main(String[] args) {
         Shape p = new Rectangle(3, 6);
         System.out.println("The area of the rectangle is " + p.getArea());
         p = new Circle(3);
         System.out.printf("The area of the circle is %.2f\n", p.getArea());
         p = new Square(4, 4);
         System.out.println("The area of the square is " + p.getArea());
     }
 }

 

enum Word{
    bit32,bit64
 }
 enum s{
     one,two,four
 }
 enum Yes_no{
     yes,no
 }
 public class CPU {
    private int fre;
     private Word wd;
     private s hu;
     private Yes_no yo;
     public CPU() {
     }
     public CPU(int fre, Word wd, s hu, Yes_no yo) {
         this.fre = fre;
         this.wd = wd;
         this.hu = hu;
         this.yo = yo;
     }
     public void show() {
         System.out.println("时钟频率:"+fre);
         System.out.print("字长:");
         switch(wd) {
         case bit32:System.out.println("32位");break;
         case bit64:System.out.println("64位");break;
         }
         System.out.print("核数:");
         switch(hu) {
         case one:System.out.println("单核");break;
         case two:System.out.println("双核");break;
         case four:System.out.println("四核");break;
        }
         System.out.print("是否支持超线程:");
         switch(yo) {
         case yes:System.out.println("是");break;
        case no:System.out.println("否");break;
         }
     }
     public static void main(String[] args) {
        CPU c=new CPU(1000,Word.bit32,s.one,Yes_no.yes);
         c.show();
     }
 }

 

三.例题

原文地址:https://www.cnblogs.com/qiangini/p/13583417.html