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访问器是取得属性值的

  • 相关阅读:
    atom编辑器中编辑C代码调用printf函数打印中文字符出现乱码
    C 库函数
    函数原型、函数声明和函数定义之间关系
    函数指针
    const 类型限定符
    AttributeError: 'str' object has no attribute '__buffer__'
    python3继承中发生的显式覆盖
    python3中的隐式继承
    黑科技
    理解jquery的$.extend()、$.fn和$.fn.extend()
  • 原文地址:https://www.cnblogs.com/dhy-com/p/12842767.html
Copyright © 2011-2022 走看看