• 第八次上机


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

    package chap1;
    
    public class Main {
        public static void main(String[] args){
        }
         char colour;
            int cpu;
            public char getYs() {
                return colour='q';
            }
            public int getCpu() {
                return cpu=865;
            }
            public void shuchu() {
                System.out.println("颜色是:"+getYs()+"	"+"cpu型号是:"+getCpu());
            }
    }
    package chap1;
    
    public class Main {
        public static void main(String[] args){
        }
        char colour;
        int  number;
        note (){
        }
        note(char colour ,int number)
        {
            this.colour=colour;
            this.number=number;
        }
        void a()
        {
            System.out.println("颜色:"+colour+"型号"+number);
            
        }
         public static void main(String[] args)
         {
             note a =new note ('a',6589);
             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 chap1;
    
    public class Main {
        String name;
        double height;
        int age;
    
       void note(String name, double height, int age) {
            this.name = name;
            this.height = height;
            this.age = age;
        }
    
        void sayHello() {
            System.out.println("hello,my name is  " + name+" "+height+"m"+" "+age+"岁");
        }
        public static void main(String[] args)
        {
        note a = new note();
         
    
        a.sayHello();
        
    
    }
    }
    package chap1;
    
    public class Main {
         String name;
            double height;
            int age;
    
           void note(String name, double height, int age) {
                this.name = name;
                this.height = height;
                this.age = age;
            }
    
            void sayHello() {
                System.out.println("hello,my name is  " + name+" "+height+"m"+" "+age+"岁");
            }
            public static void main(String[] args)
            {
            note a = new note();
             
    
            a.sayHello();
            
    
        }
        }
  • 相关阅读:
    python笔记第十一天 模块补充
    python笔记第十天 模块
    python笔记第九天 装饰器
    python笔记第八天 迭代器与生成器
    python笔记第七天 文件操作
    python笔记第六天 函数和函数的内置方法
    C语言----指针形参(指向指针的指针形参)
    NEON使用方法
    ARM NEON指令集总结
    三维变换矩阵左乘和右乘分析
  • 原文地址:https://www.cnblogs.com/ertangxuanhua/p/12759942.html
Copyright © 2020-2023  润新知