| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2948 人关注过本帖
标题:为什么这里错误
取消只看楼主 加入收藏
Q1992
Rank: 2
等 级:论坛游民
帖 子:63
专家分:24
注 册:2016-6-26
结帖率:56.25%
收藏
已结贴  问题点数:10 回复次数:2 
为什么这里错误
package java1;

public abstract class Shape {
    {
        System.out.println("执行Shaps的初始会");
    }
    private String color;
    public abstract double calPerimeter();
    public abstract String getType();
    public Shape(){}
    public Shape(String color)
    {
System.out.println("执行Shaps的初始构造器。。。");
this.color=color;
    }
    public    class Triangle extends Shape
    {
        private double a;
        private double b;
        private double c;
     public Triangle(String color ,double a , double b , double c)
     {
         if(a>=b+c||b>=a+c||c>=a+b)
         {
             System.out.println("三角型两边之和必须大于第三班");
             return;
         }
         this.a=a;
         this.b=b;
         this.c=c;
     }
     public double calPerimeter()
     {
         return a+b+c;
         
     }
     public String getType()
     {
         return "三角形";
     }
    }
    public static  class Circle extends Shape
    {
        private static final Shape sl = null;
        private double radius;
        public Circle (String color,double radius )
        {
            super(color);
            this.radius =radius;
        }
        public void setRandius(double radius)
        {
            this.radius =radius;
        }
        public double calPerimete()
        {
            return 2  *  Math.PI  *radius;
            
        }
        public String getType()
        {
            return  getColor()  +"圆形";
        }
        private String getColor() {
            // TODO 自动生成的方法存根
            return null;
        }
        @SuppressWarnings("null")
        public static void mani(String[] args)
        {
            Shape s1 = new Triangle("黑色",3,4,5);
                      ------------------------->报错
            Shape  s2 = new  Circle("黄色",3);
            
            System.out.println(sl.getType());
            
        }
        @Override
        public double calPerimeter() {
            // TODO 自动生成的方法存根
            return 0;
        }
    }
   
}    // TODO 自动生成的方法存根
   
图片附件: 游客没有浏览图片的权限,请 登录注册

搜索更多相关主题的帖子: abstract private package public double abstract private package public double 
2017-01-16 15:10
Q1992
Rank: 2
等 级:论坛游民
帖 子:63
专家分:24
注 册:2016-6-26
收藏
得分:0 
回复 2楼 GrayJerry
麻烦大神演示怎么改错误代码演示一下不胜感激
2017-01-16 19:56
Q1992
Rank: 2
等 级:论坛游民
帖 子:63
专家分:24
注 册:2016-6-26
收藏
得分:0 
回复 4楼 Q1992
package java1;

public abstract class Shape {
    {
        System.out.println("执行Shaps的初始会");
    }
    private String color;

    public abstract double calPerimeter();

    public abstract String getType();

    public Shape() {
    }

    public Shape(String color) {
        System.out.println("执行Shaps的初始构造器。。。");
        this.color = color;
    }
   
    public static class Triangle extends Shape {
        private double a;
        private double b;
        private double c;

        public Triangle(String color, double a, double b, double c) {
            if (a >= b + c || b >= a + c || c >= a + b) {
                System.out.println("三角型两边之和必须大于第三班");
                return;
            }
            this.a = a;
            this.b = b;
            this.c = c;
        }

        public double calPerimeter() {
            return a + b + c;

        }

        public String getType() {
            return "三角形";
        }
    }

    public static class Circle extends Shape {
        private static final Shape sl = null;
        private double radius;

        public Circle(String color, double radius) {
            super(color);
            this.radius = radius;
        }

        public void setRandius(double radius) {
            this.radius = radius;
        }

        public double calPerimete() {
            return 2 * Math.PI * radius;

        }

        public String getType() {
            return getColor() + "圆形";
        }

        private String getColor() {
            return null;
        }

        public static void main(String[] args) {
            Shape s1 = new Triangle("黑色", 3, 4, 5);
            Shape s2 = new Circle("黄色", 3);
            System.out.println(sl.getType());
        }

        public double calPerimeter() {
            return 0;
        }
    }

拿出来:

package java1
————————》
标记语法上有语法错误,删除这些标记
public abstract class Shape
                      ————》
                      嵌套类型 Shape  无法隐藏外层类型
   {
    {
        System.out.println("执行Shaps的初始会");
    }
    private String color;

    public abstract double calPerimeter();

    public abstract String getType();

    public Shape() {
    }

    public Shape(String color) {
        System.out.println("执行Shaps的初始构造器。。。");
        this.color = color;
    }
   
    public static class Circle extends Shape {
        private static final Shape sl = null;
        private double radius;

        public Circle(String color, double radius) {
            super(color);
            this.radius = radius;
        }

        public void setRandius(double radius) {
            this.radius = radius;
        }

        public double calPerimete() {
            return 2 * Math.PI * radius;

        }

        public String getType() {
            return getColor() + "圆形";
        }

        private String getColor() {
            return null;
        }

        public static void main(String[] args) {
            Shape s1 = new Triangle("黑色", 3, 4, 5);
            Shape s2 = new Circle("黄色", 3);
            System.out.println(sl.getType());
        }

        public double calPerimeter() {
            return 0;
        }
    }
}

class Triangle extends Shape {
    private double a;
    private double b;
    private double c;

    public Triangle(String color, double a, double b, double c)
          ——————》报错
        嵌套类型Triangle重复

  {
        if (a >= b + c || b >= a + c || c >= a + b) {
            System.out.println("三角型两边之和必须大于第三班");
            return;
        }
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public double calPerimeter() {
        return a + b + c;

    }

    public String getType() {
        return "三角形";
    }
}
}
2017-01-18 18:26
快速回复:为什么这里错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.070620 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved