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

    1.

    package llll;
    
    public class student {
    
        String  name=new String("该学生还未命名"); 
        double achievement;   
         
    public student(){   
    }
    
     public student(String str,double achievement){ 
            this.name=str;
            this.achievement=achievement;
     }
     
     void set(String str,double achievement){  
     this.name=str;
     this.achievement=achievement;
         }
    
    void get(){
     
            System.out.println("该学生姓名为:"+name);
            System.out.println("该学生成绩为:"+achievement);
         }
    }
    package llll;
    
    public class t {
           public static void main(String args[]){
    student A=new student();
    A.set(" 小明",90);
    A.get();
    student B=new student("小王",60);
    B.get();
    }
    
    }

    2

    package finish;
    
    
    public class ttt {
    
        public void Test() {
            System.out.println("无参的调用方法被调用了");
        }
    }
    package finish;
    
    public class b extends ttt {
        
    
            public static void main(String[] args) {
                ttt z=new ttt();
                z.Test();
            }
    
        }

    3.

    package finish;
    
    
    public class ttt {
    
        String name;
        String color;
    
        public static void main(String[] args) {
            ttt c1=new ttt("benchi","红色");
            ttt c2=new ttt("dazhong","黑色");
        }
    
        public ttt(String name1, String color1) {
            name = name1;
            color = color1;
            run();
        }
    
        public void run() {
            System.out.println(color + "的" + name + "正在跑。");
        }
    
    }

    4.

    package finish;
    
    
    public class ttt {
    
        public static void main(String[] args) {
              get(9,13);
            }
    
            public static void get(int i, int j) {
                System.out.println(i + j);
            }
        }

    5.

    封装就是:隐藏对象的属性和实现细节,仅对外提供公共访问方式。
    封装的好处:
    重用;
    不必关心具体的实现;
    面向对象三大特征之一;
    具有安全性
    set访问器是给属性赋值的,get访问器是取得属性值的

  • 相关阅读:
    nodejs设置NODE_ENV环境变量(2)
    CentOS6.8系统安装Node
    mongodb3.X权限配置
    在centos7中添加一个新用户并授权
    CentOS 7.0启用iptables防火墙
    Nginx编译参数大全 configure参数中文详解
    Linux(centos)系统各个目录的作用详解
    CentOS 6.5_X64下安装MongoDB数据库
    vue-cli 发布(译)
    Linux下的crontab定时执行任务命令详解
  • 原文地址:https://www.cnblogs.com/dhy-com/p/12842767.html
Copyright © 2011-2022 走看看