• 第八周上机练习


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

    package pra;
    
    public class Laptop {
        char color;
        int model;
        
        public Laptop() {
            
        }
        
        public Laptop(char color, int model) {
            this.color = color;
            this.model = model;
        }
        
        public void a() {
            System.out.println("颜色:" + color + "  型号:" + model);
        }
        
        public static void main(String[] args) {
            Laptop a = new Laptop('b', 54210);
            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 pra;
    
    public class Person {
        String name;
        int age;
        double height;
        public void sayHello() {
            System.out.println("hello my name is " + this.name);
        }
        public void getValue(String name,int age,double height) {
            this.name = name;
            this.age = age;
            this.height = height; 
        }
        public static class PersonCreate {
            public static void main(String[] args) {
                Person p1 = new Person();
                p1.getValue("zhangsan",33,1.73);
                p1.sayHello();
                Person p2 = new Person();
                p2.getValue("lishi",44,1.74);
                p2.sayHello();
            }
        }
    
    
    }

  • 相关阅读:
    *Convert Sorted Array to Binary Search Tree
    *Count Complete Tree Nodes
    *Binary Tree Paths
    Invert Binary Tree
    *Kth Smallest Element in a BST
    **Lowest Common Ancestor of Two Nodes in a Binary Tree
    Lowest Common Ancestor of a Binary Search Tree
    *Sum root to leaf number
    subversion javahl
    mongodb从来没有说它写成功了。
  • 原文地址:https://www.cnblogs.com/menfanbo/p/12759707.html
Copyright © 2020-2023  润新知