java面试题

package cn.interview;


public class StaticDemo implements Interf{
	public static void main(String[] args) {
		StaticDemo demo = new StaticDemo();
		demo.method();//参考Method.invoke(),静态方法调用不管前面对象是否为空
		
		
		CharSequence charSequence = "aa";
		method(charSequence);//传什么调用什么
		
		Interf interf = new StaticDemo();
		interf.method1("String");//多态
		
	}
	
	private static void method(CharSequence charSequence) {
		System.out.println("CharSequence");
	}
	private static void method(String s) {
		System.out.println("String");
	}


	static void method(){
		System.out.println("no nullpointer");
	}


	@Override
	public void method1(CharSequence charSequence) {
		System.out.println("method1 implement-->"+charSequence);
	}
	
	
}


interface Interf{
	void method1(CharSequence charSequence);
}

结果:

no nullpointer
CharSequence
method1 implement-->String


你可能感兴趣的:(java面试题)