千峰逆战班,Day19

在千锋逆战班学习的第19天。

人若是看透了自己,便不会再小看别人。

今天我学习了JAVA课程的 部分关于接口、成员内部类的知识。

中国加油!!!武汉加油!!!千锋加油!!!我自己加油!!!

总结:

接口:

               先有接口,再调用,再实现

内部类:

               概念:在类的内部再定义一个完整的类。

               可为外部类提供必要的内部功能组件。

成员内部类:

               重名时,会优先访问内部类属性。

               外部类的一个实例部分,创建内部类对象时,必须依赖外部对象。

               Outer out=new Outer();

               Outer.Inner in=out.new Inner();

 

习题:

Comparable   student

package comparable;

public class Student implements Comparable<Student>{
	String name;
	int age;

	public Student(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}

	@Override
	public int compareTo(Student o) {
		if(o.age>this.age){
			return 1;
		}if(o.age<this.age){
			return -1;
		}
		return 0;
	}
}
package comparable;

import java.util.Arrays;

public class TestStudentsAge {

	public static void main(String[] args) {

		Student[] ss=new Student[]{
				new Student("Tom",25),
				new Student("Mic",22),
				new Student("Anny",26),
				new Student("Jan",23)};
		
		Arrays.sort(ss);
		
		for(int i=0;i<ss.length;i++){
			System.out.println(ss[i].name+"\t"+ss[i].age);
		}
	}
}
发布了8 篇原创文章 · 获赞 3 · 访问量 511

猜你喜欢

转载自blog.csdn.net/Dukeo00o/article/details/104532679
今日推荐