30道JAVA英文面试题

本文列举了30道关于Java的面试问题,涵盖了类与对象、多线程、异常处理、内存管理等多个核心知识点。例如,如何将错误消息重定向到文件,接口与抽象类的区别,何时使用同步块与同步方法,以及如何判断是否需要显式类型转换等。此外,还讨论了构造函数与普通方法的不同,包的作用,以及不同版本JDK的差异等。
摘要由CSDN通过智能技术生成

* Q1. How could Java classes direct program messages to the system console, but error messages, say to a file?.
The class System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:


Stream st = new Stream(new FileOutputStream("output.txt")); System.setErr(st); System.setOut(st);

* Q2. What's the difference between an interface and an abstract class?

A. An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.

* Q3. Why would you use a synchronized block vs. synchronized method?

A. Synchronized blocks place locks for shorter periods than syn

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值