• java学习——构造类


    package my_project;
    
    public class my_first_class {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Point p1 = new Point();
            p1.setX(8.0);
            p1.setY(9.0);
            Circle c1 = new Circle();
            c1.setCentre(p1);
            c1.setRadius(1.0);//设置c1的半径
            
            System.out.println("圆心(x,y)= " + "(" + c1.getCentre().getX() + "," +
                    + c1.getCentre().getY() + ")");
            System.out.println("圆的半径 = " + c1.getRadius());
            System.out.println("圆的面积= " + c1.getArea());
            System.out.println("圆的周长= " + c1.getCircleLong());
    
        }
    
    }
    class Point{
        
        private double x;
        private double y;
        
        public double getX()
        {
            return x;
        }
        
        public void setX(double x)
        {
            this.x=x;
        }
        
        public double getY()
        {
            return y;
        }
        public double setY(double y)
        {
            return this.y=y;
        }
    }
    
    class Circle{
        
        private Point centre;
        
        private double radius;
        
        final static double PI = 3.1415926;//PI常量(最终类变量)
        
        public Point getCentre()
        {
            return centre;
        }
        
        public void setCentre(Point centre)
        {
            this.centre = centre;
        }
        
        public double getRadius()
        {
            return radius;
        }
        
        public void setRadius(double radius)
        {
            this.radius=radius;
        }
        
        public double getArea()
        {
            return PI*Math.pow(radius,2);
        }
        
        public double getCircleLong()
        {
            return 2*PI*radius;
        }
    }

     

    构造学生类:

    package hello;
    
    public class Student {
        
        String xm,xh,xb;
        
        Student(){
        }
        
        public Student(String xm, String xh, String xb){
            this.xm=xm;
            this.xh=xh;
            this.xb=xb;
        }
        
        public String getXm() {
            return xm;
        }
    
        public void setXm(String xm) {
            this.xm = xm;
        }
    
        public String getXh() {
            return xh;
        }
    
        public void setXh(String xh) {
            this.xh = xh;
        }
    
        public String getXb() {
            return xb;
        }
    
        public void setXb(String xb) {
            this.xb = xb;
        }
    
    
        public String toString() {
            return "Student [xm=" + xm + ", xh=" + xh + ", xb=" + xb + "]";
        }
        
        public void Print() {
            System.out.println("Student [xm=" + xm + ", xh=" + xh + ", xb=" + xb + "]");
        }
    
    }
  • 相关阅读:
    png图片透明在ie6中显示问题
    DIV背景图片在Firefox下不显示,IE下正常
    整理:兼容 IE、Firefox、Opera和Safari
    IE6背景消失问题
    鼠标悬停换图片或背景
    网站团队组建方案
    CSS兼容IE6,IE7,FF的技巧
    打造MySQL版的最新IP数据库
    域名判断后跳转——PHP跳转代码_ASP跳转代码_JS跳转代码
    IE6文字消失、背景圖消失之謎
  • 原文地址:https://www.cnblogs.com/caiyishuai/p/9755255.html
Copyright © 2020-2023  润新知