您的位置:首页 > 其它

Interview Q&A and Experience

2016-04-27 13:41 513 查看
http://blog.sina.com.cn/s/blog_814f5e700101flnw.html

如果类a继承类b,实现接口c,而类b和接口c中定义了同名变量,请问会出现什么问题?如下代码:

public interface C {
public int count = 1;
}
public abstract class B {
public int count = 2;
}
public class A extends B implements C {

public void print() {
// Compile Error: The field count is ambiguous
System.out.println(count);
}

public static void main(String[] args) {
new A().print();
}
}


答案:Compile Error: The field count is ambiguous。就象在同时import java.util和java.sql两个包时直接声明Date一样。对于父类的变量,可以用super.x来明确(输出的是2),而接口的属性默认隐含为 public static final.所以可以通过A.x来明确(输出的是1)。

transient和volatile是java关键字吗?

https://en.wikibooks.org/wiki/Java_Programming/Keywords/transient

http://www.javamex.com/tutorials/synchronization_volatile.shtml

http://javarevisited.blogspot.com/2011/06/volatile-keyword-java-example-tutorial.html

抽象类和接口有什么区别?

http://www.javatpoint.com/difference-between-abstract-class-and-interface

http://stackoverflow.com/questions/1913098/what-is-the-difference-between-an-interface-and-abstract-class

能说一下java的反射(reflection)机制吗

http://lavasoft.blog.51cto.com/62575/43218/

http://stackoverflow.com/questions/37628/what-is-reflection-and-why-is-it-useful

http://www.programcreek.com/2013/09/java-reflection-tutorial/

在java中怎样实现多线程

extends Thread

implement Runnable
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  interview