• 5-7上机练习


    package h_m_5_7;
    //第一题
    public class Student {
        private String name;
        private int score;
        public Student() {
            // TODO Auto-generated constructor stub
        }
        
            
        public Student(String name, int score) {
            super();
            this.name = name;
            this.score = score;
        }
    
    
        public String getName() {
            return name;
        }
    
    
        public void setName(String name) {
            this.name = name;
        }
    
    
        public int getScore() {
            return score;
        }
    
    
        public void setScore(int score) {
            this.score = score;
        }
    
    
        @Override
        public String toString() {
            return "Student [name=" + name + ", score=" + score + "]";
        }
    
    
        public static void main(String[] args) {
            Student s1= new Student();
            s1.setName("王兆明");
            s1.setScore(100);
            System.out.println(s1);
            Student s2 = new Student("嘟嘟", 60);
            System.out.println(s2);
        }
    
    }
    package h_m_5_7;
    /*
     * 第二题
     */
    public class Person {
    public Person() {
        System.out.println("这个构造方法被调用了");
    }
        public static void main(String[] args) {
            Person s = new Person();
        }
    
    }
    package h_m_5_7;
    /*
     * 第三题
     */
    public class Car {
        String name;
        String color;
        
        public Car(String name, String color) {
            super();
            this.name = name;
            this.color = color;
        }
        public void run(){
            System.out.println("正在跑");
        }
    
        public static void main(String[] args) {
            Car c = new Car("奥迪", "black");
            c.run();
        }
    
    }
    package h_m_5_7;
    /*
     * 第四题
     */
    public class Demo {
        public static void sum(int x,int y){
            System.out.println("sum:"+(x+y));
        }
        public static void main(String[] args) {
            Demo d= new Demo();
            d.sum(20, 30);
        }
    
    }
    package h_m_5_7;
    
    public class Demo02 {
        /*
         * 第五题
         * 什么是封装 及其get,set 方法的好处
         * 
         * 封装把对象的所有组成部分组合在一起,
         * 封装定义程序如何引用对象的数据,封装实际上使用方法将类的数据隐藏起来,
         * 控制用户对类的修改和访问数据的程度。 
         * 适当的封装可以让程式码更容易理解和维护,也加强了程式码的安全性。
         */
    }
  • 相关阅读:
    python 输入和输出
    python 深入模块和包
    python 模块
    python 字典 注意点
    javaNIO核心概念
    redis使用bit做只有两种情况的“状态“统计(如是否在线的用户统计)
    mysqlbinlog二三事儿
    mysql在windows下的服务安装
    javassist标识符
    使用redis调用lua脚本的方式对接口进行限流
  • 原文地址:https://www.cnblogs.com/wzm7282/p/12841590.html
Copyright © 2020-2023  润新知