Interview Q&A and Experience

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值