zoukankan      html  css  js  c++  java
  • 第十周上机作业

    1.public class Student {
        String name;
        double score;
    
        public Student() {
    
        }
    
        public Student(String name, int score) {
            this.name = name;
            this.score = score;
        }
    
        void set(String name, int score) {
            this.name = name;
            this.score = score;
        }
    
        void get() {
            System.out.println("学生姓名:" + name);
            System.out.println("学生成绩:" + score);
    
        }
    
    }
    public class Student {
        String name;
        double score;
    
        public Student() {
    
        }
    
        public Student(String name, int score) {
            this.name = name;
            this.score = score;
        }
    
        void set(String name, int score) {
            this.name = name;
            this.score = score;
        }
    
        void get() {
            System.out.println("学生姓名:" + name);
            System.out.println("学生成绩:" + score);
    
        }
    
    }
    2.public class Person {
        public Person() {
            System.out.println("无参的构造方法被调用了...");
        }
    }
    public class Text {
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Person p = new Person();
    
        }
    }
    3.public class Car {
        String name;
        String color;
    
        public void run() {
            System.out.println(color + "的" + name + "时速200");
        }
    
    }
    public class Text {
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Car a = new Car();
            a.color = "橙色";
            a.name = "迈凯伦";
            a.run();
    
        }
    }
    4.public class Demo {
        public static int get(int a, int b) {
            return a + b;
        }
    }
    public class Text {
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            int sum = Demo.get(10, 20);
            System.out.println("两个数的和是:" + sum);
    
        }
    }

    5.说一下什么是封装, 使用封装的好处。什么是get,set访问器

    封装就是将对象中的实现细节隐藏,不被外界直接访问。

    好处:提高代码的安全性

    set是赋值,get是获取值。

  • 相关阅读:
    40个极简WordPress主题
    一些上流的CSS3图片样式
    15个最好的 HTML5 视频播放器
    优秀的IOS界面
    25 个超棒的 WordPress 主题(2012)
    Codekit 为Web前端打造的全能型神器(附推荐各种工具)
    10 个精彩的、激发灵感的 HTML5 游戏
    20个非常绚丽的 CSS3 特性应用演示
    25+ 个免费精美的商业风格的 WordPress 主题
    10 款非常棒的CSS代码格式化工具推荐
  • 原文地址:https://www.cnblogs.com/wudongyang521/p/12842235.html
Copyright © 2011-2022 走看看