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

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

    package chap01;
    
    public class book {
        char colour;
        int cpu;
    
        public void info() {
            System.out.println("颜色是" + colour);
            System.out.println("型号是" + cpu);
        }
    
    }
    package chap01;
    
    public class Test02 {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            book a = new book();
            a.colour = '蓝';
            a.cpu = 123;
            
            a.info();
        }
    
    }

    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 chap01;
    
    public class Person {
        String name;
        double length;
        int age;
    
        public void sayHello() {
            System.out.println("hello,my name is" + name);
            System.out.println("年龄是 "+age);
            System.out.println("身高是 "+length);
        }
    
    }
    package chap01;
    package chap01;
    
    public class PTest03 {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Person a1 = new Person();
            Person a2 = new Person();
    
            a1.name = "zhangsan";
            a1.length = 1.73;
            a1.age = 33;
    
            a1.sayHello();
    
            a2.name = "lishi";
            a2.length = 1.74;
            a2.age = 44;
    
            a2.sayHello();
    
        }
    
    }

  • 相关阅读:
    win2008服务器,fastCGI完美设置教程
    IIS7中配置FastCGI运行PHP
    Apple 移动设备绑定动态生成元素点击事件$(document).on('click',element,callback)失效解决方法
    MacOS Catalina 10.15 brew 安装 PHP 和 使用 pecl 安装 Mcrypt
    Redis 列表命令记录
    Redis hash类型命令
    Redis 字符串命令
    Redis 通用命令记录
    Redis 三种启动方式
    Mac 使用 wget 安装 Redis3.0
  • 原文地址:https://www.cnblogs.com/wxyailjy/p/12759754.html
Copyright © 2011-2022 走看看