zoukankan      html  css  js  c++  java
  • 第八周上机

    3、定义一个笔记本类,该类有颜色(char)和cpu
    型号(int)两个属性。 [必做题]
    • 3.1 无参和有参的两个构造方法;有参构造方法可
    以在创建对象的同时为每个属性赋值;
    • 3.2 输出笔记本信息的方法
    • 3.3 然后编写一个测试类,测试笔记本类的各个
    方法。

    package as;
    
    public class Macbook {
        char color;
        int cpu;
        Macbook() {
    
        }
        Macbook(char color, int cpu) {
            this.color = color;
            this.cpu = cpu;
        }
        void a() {
            System.out.println("颜色:" + color + "  型号:" + cpu);
        }
    }
    package as;
    
    public class unll {
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Macbook a = new Macbook('a', 8888);
            a.a();
        }
    }

     5、定义两个类,描述如下: [必做题]
    • 5.1定义一个人类Person:
    • 5.1.1定义一个方法sayHello(),可以向对方发出问
    候语“hello,my name is XXX”
    • 5.1.2有三个属性:名字、身高、体重
    • 5.2定义一个PersonCreate类:
    • 5.2.1创建两个对象,分别是zhangsan,33岁,1.73
    ;lishi,44,1.74
    • 5.2.2分别调用对象的sayHello()方法。

    package as;
    
    public class Person {
        String name;// 姓名
        double height;// 身高
        double age ;// 年龄
        Person(String name, double height, double age) {
            this.name = name;
            this.height = height;
            this.age = age;
        }
        void sayHello() {
            System.out.println("hello,my name is  " + name+" "+height+"m"+" "+age+"岁");
        }
    
    }
    package as;
    
    public class Constructor {
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Person a = new Person("zhangsan", 1.73, 33);
            Person b = new Person("lishi", 1.74, 44);
            a.sayHello();
            b.sayHello();
        }
    }

  • 相关阅读:
    js 数组扁平
    leetcode 15 三数之和
    leetcode 1 两数之和
    编写一个自定义事件类,包含on/off/emit/once方法
    css常见双栏和三栏布局
    关于js中this指向的问题
    函数防抖和节流
    ie6 js报错汇总
    windows PHP配置随笔
    上传文件表单file,限制上传文件类型的方法--参数accept
  • 原文地址:https://www.cnblogs.com/zxp-0101/p/12759653.html
Copyright © 2011-2022 走看看