• 4.23作业


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

     1 package wyyyy;
     2 public class macbookpro {
     3         char color;
     4         int model;
     5 
     6         macbookpro() {
     7 
     8         }
     9 
    10         macbookpro(char color, int model) {
    11             this.color = color;
    12             this.model = model;
    13         }
    14 
    15         void a() {
    16             System.out.println("颜色:" + color + "  型号:" + model);
    17         }
    18 
    19         public static void main(String[] args) {
    20             macbookpro a = new macbookpro('a', 2020);
    21             a.a();
    22         }
    23     }

    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()方法。

     1 package wyyyy;
     2 public class person {
     3         String name;// 名字
     4         double height;// 身高
     5         int age;// 年龄
     6 
     7         person(String name, double height, int age) {
     8             this.name = name;
     9             this.height = height;
    10             this.age = age;
    11         }
    12 
    13         void sayHello() {
    14             System.out.println("hello " + name+" "+height+"m"+" "+age+"岁");
    15         }
    16     }
     1 package wyyyy;
     2 
     3 public class Constructor {
     4 
     5     public static void main(String[] args) {
     6         // TODO Auto-generated method stub
     7         person a = new person("wangyuyan", 1.9, 20);
     8         person b = new person("meinv", 1.99, 18);
     9         a.sayHello();
    10         b.sayHello();
    11 
    12     }
    13 
    14
  • 相关阅读:
    poj 2002 Squares 几何二分 || 哈希
    hdu 1969 Pie
    hdu 4004 The Frog's Games 二分
    hdu 4190 Distributing Ballot Boxes 二分
    hdu 2141 Can you find it? 二分
    Codeforces Round #259 (Div. 2)
    并查集
    bfs
    二维树状数组
    一维树状数组
  • 原文地址:https://www.cnblogs.com/WangYYY/p/12759832.html
Copyright © 2020-2023  润新知