zoukankan      html  css  js  c++  java
  • 第八周上机练习(4.23)

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

    package test111;

    public class bijibendiannao {
             char color;
            int model;

     bijibendiannao() {

          }

    bijibendiannao(char color, int model) {
              this.color = color;
              this.model = model;
        }

              void a() {
             System.out.println("颜色:" + color + " 型号:" + model);
       }

               public static void main(String[] args) {
              bijibendiannao a = new bijibendiannao('a', 77777);
              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 test;
    public class person {
              String name;
              double lengh;
               int age;
    public void sayhello() {
              System.out.println("hello,my name is "+name);
              }
          }

    package test;

    public class personcrate {
    public static void main(String[] args) {

              person p=new person();

              p.name="zhangsan";
              p.lengh=1.73;
              p.age=33;
              p.sayhello();
               person w=new person();
              w.name="lishi";
               w.lengh=1.74;
               w.age=44;
               w.sayhello();

                    }

           }

     

  • 相关阅读:
    文字转语音功能
    windows定时计划任务
    写电子合同,爬过的坑,趟过的雷,犯过的错,都是泪
    前端应该如何去认识http
    I/O理解
    观察者模式
    js --代理模式
    js --策略模式
    js --单例模式
    js 单线程 异步
  • 原文地址:https://www.cnblogs.com/fanbudufan/p/12759843.html
Copyright © 2011-2022 走看看