java入门学习

继承性 覆写 多态性

//class A{
//	public void fum() {
//		System.out.println("A中的方法");
//	}	
//}
//class B extends A{
//	public void fum() {
//		System.out.println("B中的方法");
//	}
//	public void fumB(){
//		System.out.println("奥利给");
//	}
//}
//
//public class Demo4{
//	public static void main(String args[]) {
//		B b=new B();
//		tt(b);
//	}
//	public static void tt(A a) {
//		a.fum();
//		if(a instanceof B) {
//			B b=(B) a;
//			b.fumB();
//		}
//	}
//}


//class Array{
//	private int data[];
//	private int len;
//	private int x=0;
//	public Array(int len) {
//		if(len>0)
//			this.len=len;
//		else
//			this.len=1;
//		this.data=new int[this.len];
//	}
//	public void addArray(int t) {
//		System.out.println(this.x<len);
//		if(this.x<len) {
//			this.data[x++]=t;	
//		}
//	}
//	public int getLen() {
//		return this.len;
//	}
//	public int[] getInfo() {
//		return this.data;
//	}
//}
//class A extends Array{
//	public A(int len){
//		super(len);
//	}
//	public void getSort() {
//		java.util.Arrays.sort(this.getInfo());
//		for(int i=0;i<this.getLen();i++) {
//			System.out.println(this.getInfo()[i]);
//		}
//	}
//}
//class B extends Array{
//	public B(int len){
//		super(len);
//	}
//	public int[] getData() {
//		int head=0;
//		int tail=this.getLen()-1;
//		while(head<=tail) {
//			int t=getInfo()[head];
//			getInfo()[head]=getInfo()[tail];
//			getInfo()[tail]=t;
//			tail--;
//			head++;	
//		}
//		return this.getInfo();
//	}
//}
//public class Demo4{
//	public static void main(String args[]) {
//		B a =new B(5);
//		a.addArray(1);
//		a.addArray(2);
//		a.addArray(3);
//		a.addArray(10);
//		a.addArray(5);
//		a.addArray(-789);
//		a.getData();
//		for(int i=0;i<a.getLen();i++) {
//			System.out.println(a.getInfo()[i]);
//		}
//	}
//}


//验证方法的覆写
//class A{
//	private String name;
//	public void fum() {
//		System.out.println("A中的方法");
//	}
//}
//class B extends A{
//	
//	public void fum() {
//	System.out.println("B中的方法");
//	}
//}
//class C extends A{
//	public void fum() {
//		System.out.println("C中的方法");
//	}
//}
//public class Demo4{
//	public static void main(String args[]) {
//		new B().fum();
//		new C().fum();
//	}
//}



//验证了B类继承A类
//class A{
//	private String name;
//	private double price;
//	public A(String name,double price){
//		System.out.println("A 类构造方法");
//		this.name=name;
//		this.price=price;
//	}
//	public String getName() {
//		return this.name;
//	}
//	public double getPrice() {
//		return this.price;
//	}
//}
//class B extends A{
//	private String school;
//	public B(String name,double price,String school) {
//		super(name,price);
//		System.out.println("B 类构造方法");
//		this.school=school;
//	}
//	public String getInfo() {
//		return "姓名:"+this.getName()+"
价格:"+this.getPrice()+"
学校:"+this.school;
//	}
//}
//public class Demo4{
//	public static void main(String args[]) {
//		B b=new B("老狗",250,"清华");
//		System.out.println(b.getInfo());
//	}
//}
原文地址:https://www.cnblogs.com/fxzemmm/p/14847961.html