首页 > 代码库 > 2016.10.24 继续学习

2016.10.24 继续学习

今天继续学习,进入面向对象的学习.

1.输出换行可以这样输出

System.out.println();

2.数组学得有点蒙....

public class PracMultiArray {
    public static void main(String[] args) {
        int[][] a1 = {{1, 2, 4}, {3, 1, 2}, {14, 5, 3}};
        System.out.println(a1[1][2]);
        for(int i=0;i<a1.length;i++){
            for(int j=0;j<a1[i].length;j++){
                System.out.print(a1[i][j]+" ");
            }
            System.out.println();
        }
    }
}

3.类就是事物的集合和抽象,他所代表的就是这一类事物共用的一些行为和属性

4.java类的默认修饰符是default,介于protected和private之间

5.没有构造方法的情况下new一个构造方法,系统默认会赋一个初值,一般为空/0/false

6.this.name=name,前name是该类定义的一个属性,后面的name是构造函数的参数.

7.对象是类的实例化.

8.方法的重载

public class PracClassOverload {
    int age;
    String name;
    char gender;

    void tax(){
        System.out.println("helloworld");
    }

    void tax(int age){
        System.out.println("Mavic,man,"+age);
    }

    void tax(String name){
        System.out.println(name+",man,6");
    }

    void tax(char gender){
        System.out.println("Martin,10,"+gender);
    }

    public static int sayHello(int a,int b){
        return a+b;
    }

    public static void main(String[] args){
        int a=sayHello(6,8);
        PracClassOverload p=new PracClassOverload();
        p.tax();
        p.tax(‘m‘);
        p.tax("Mavic");
        p.tax(18);
    }
}

9.构造方法的重载

public class PracClassGouZaoFangFa {
    int age;
    String name;
    char gender;

    public PracClassGouZaoFangFa(){}

    public PracClassGouZaoFangFa(String name){
        this.name=name;
    }

    public PracClassGouZaoFangFa(String name,int age){
        this(name);//可以这样用
        this.age=age;
    }

    public PracClassGouZaoFangFa(String name,int age,char gender){
        this(name,age);//可以这样用
        this.gender=gender;
    }
}

10.构造方法重载的调用

public class PracClassVerify {
    public static void main(String[] args) {
        PracClassGouZaoFangFa s1 = new PracClassGouZaoFangFa();
        Prac(s1);
        PracClassGouZaoFangFa s2 = new PracClassGouZaoFangFa("Mavic");
        Prac(s2);
        PracClassGouZaoFangFa s3 = new PracClassGouZaoFangFa("Mavic", 18);
        Prac(s3);
        PracClassGouZaoFangFa s4 = new PracClassGouZaoFangFa("Mavic", 8, ‘m‘);
        Prac(s4);
    }
    
//通过定义一个静态方法来对构造方法进行调用
public static void Prac(PracClassGouZaoFangFa s) { System.out.println("age:" + s.age); System.out.println("name:" + s.name); System.out.println("gender:" + s.gender); System.out.println("--------haha--------"); } }

今天来了个徒弟......无伤大雅,幸运的是志邦还留着我以前发的图,星期六看看情况拉起,下星期完结这个java吧,准备入门android开发,就这样了,洗澡`~~~

2016.10.24 继续学习