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

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

    package project1;
    
    
    public class a1 {
        char color;
        int model;
    
        a1() {
    
        }
    
        a1(char color, int model) {
            this.color = color;
            this.model = model;
        }
    
        void a() {
            System.out.println("颜色:" + color + "  型号:" + model);
        }
    
        public static void main(String[] args) {
            a1 a = new a1('白', 9527);
            a.a();
        }
    
    }
    

      2

    package project1;
    
    
    public class a1 {
         public String name;
            double sg;
            int tz;
            int age;
            public a1() {
                
            }
    
            public a1(String name ,double sg,int tz,int age) {
                this.name=name;
                this.sg=sg;
                this.tz=tz;
                this.age=age;
            }
            public void sayHello() {
                System.out.println("hello my name is " + this.name);
            }
    }
    

      

    package project1;
    
    public class Constructor {
        public static void main(String[] args) {
            // TODO Auto-generated method stub
             a1 i1=new a1();
             i1.name="zhangsan";
             i1.sg=1.73;
             i1.tz=300;
             i1.age=33;
             
             a1 i2=new a1();
             i2.name="lishi";
             i2.sg=1.74;
             i2.tz=500;
             i2.age=44;
             
             i1.sayHello();
        }
    }
    

      

  • 相关阅读:
    字符串和数字的相互转换
    考研_计算机网络
    修改Win+E映射
    BFS总结
    关于—— !important
    css中hack是什么
    轮播图 Swiper4.x 代码模板
    微信小程序---数组操作
    小程序-----button 分享按钮
    微信小程序从子页面退回父页面时的数据传递 wx.navigateBack()
  • 原文地址:https://www.cnblogs.com/y611lx/p/12762963.html
Copyright © 2011-2022 走看看