zoukankan      html  css  js  c++  java
  • 第六次上机作业

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

    package com.run.test;
    
    public class noteBook {
        char color;
        int  model;
        noteBook(){    
        }
        noteBook(char color,int model){
            this.color=color;
            this.model=model;
        }
        public void info() {
            System.out.println("笔记本信息:"+color+" "+model);
        }
    }
    
    package com.run.test;
    
    public class test {
    
        public static void main(String[] args) {
            noteBook a=new noteBook('',20);
            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 com.run.test;
    
    public class Person {
        String name;
        double height;
        int age;
        Person(){
        }
        Person(String name,double height,int age){
            this.name=name;
            this.height=height;
            this.age=age;
        }
        public void sayHolle() {
            System.out.println("hello my name is "+name);
        }
        
    }
    
    package com.run.test;
    
    public class PersonCreate {
    
        public static void main(String[] args) {
            Person a=new Person("zhangsan", 1.73, 33);
            a.sayHolle();
            Person b=new Person("lishi", 1.74, 44);
            b.sayHolle();
        }
    
    }
  • 相关阅读:
    微软 软件的 一组堆成快捷键
    C#事件 的讲解
    软件缺陷分析的几种方法
    一个长三角人对深圳的看法 (转)
    一次LoadRunner的CPC考试经历
    测试是一门武功
    ORACLE的性能测试经验总结
    深圳测试协会第九次论坛在深圳举行
    10月28日参加了IBM的产品推介会
    什么是web安全性测试?
  • 原文地址:https://www.cnblogs.com/rozenscarlet/p/12759876.html
Copyright © 2011-2022 走看看