脚本宝典收集整理的这篇文章主要介绍了java面试题,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
public class ParameterPass {
public static void main(String[] args) {
int i = 0;
AddTwo(i++);
System.out.PRintln(i);
}
static void AddTwo(int i) {
i += 2;
}
}
1
2. 下面那些是 Java关键字?
default,null,String,throws,loing,true
3. 编译并运行下面的程序,结果是什么?
public class MyClass{
public static void main(String[] args) {
String s = "java 你好";
System.out.println(s.length);//编译错误,如果是正确长度是7,底层是char数组
}
}
class RuiguClass {
int i = 10;
private static float pi = 3.0f;//1
public static void main(String[] args) {
public int i = 20;//编译错误, 局部变量不能使用 修饰符
final double d = 4.0d;//3
System.out.println(i + d + pi);
}
}
class Mytest extends Test {
public MyTest() {
System.out.println("s2");
}
}
class Test {
public static void main(String args[]) {
new MyTest(); //s1 s2
}
public Test() {
System.out.println("s1");
}
}
class MyClass{
public static void main(String args[]){
List list = new ArrayList();
list.add("1");
list.add("2");
list.add(1,"3");
List list2 = new LinkedList(List);
list.addAll(list2);
list2 = list.subList(2,5);
list2.clear();
System.out.println(list); //[1, 3, 2]
}
}
class MyClass{
public static void main(String[] args){
String st1="str1";
String st2="str2";
String st3="str3"
st1.concat(st2);
System.out.println(st3.concat(st1));//str3str1
}
}
class MyClass extends Thread {
@override
public void run() {
try {
for (int i = 0; i < 5; i++) {
if (i > 2) interrupt();
sleep(1000);
if (interrupted()) break;
}
} catch (InterruptedException e) {
e.printStackTrace();
System.out.println(" caught");
}
}
public static void main(String[] args) {
MyClass myClass = new MyClass();
myClass.start();
}
}
请选择正确的答案:1、1 2、1 2 3、1 caught、1 2 caught、1 2 3 caught、以上都不是
以上是脚本宝典为你收集整理的java面试题全部内容,希望文章能够帮你解决java面试题所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。