zoukankan      html  css  js  c++  java
  • 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 + "]");
        }
    
    }
  • 相关阅读:
    HDFS文件系统上传时序图 PB级文件存储时序图
    HDFS 文件系统流程图。PB级文件存储时序图。
    HBase 1.1.2 优化插入 Region预分配
    InputStream、OutputStream
    StringBuffer_StringBuilder
    java中的字符串
    升级的三个因素
    装饰设计模式
    IO字符流之读写缓冲区(BufferedWriter、BufferedReader)
    IO(FileWriter/FileReader)字符流:文件的写入、续写、读
  • 原文地址:https://www.cnblogs.com/caiyishuai/p/13270868.html
Copyright © 2011-2022 走看看