------
Java培训、Android培训、iOS培训、.Net培训、期待与您交流! -------
Java基础---练习题
1.写出程序结果
<span style="font-size:18px;">class Demo
{
public static void func()
{
try
{
{
throw new Exception();
}
finally
{
System.out.println("B");
}
}
}
public static void main(String[] args)
{
try
{
func();
System.out.println("A");
}
catch (Exception e)
{
System.out.println("C");
}
System.out.println("D");
}
}</span>
结果是:编译失败,如果func上声明了该异常,
结果是:
B
C
D
2.写出程序结果
<span style="font-size:18px;">class Test
{
Test()
{
System.out.println("Test");
}
}
class Demo extends Test
{
Demo()
{
System.out.println("Demo");
}
public static void main(String[] args)
{
new Demo();
new Test();
}
}</span>
结果是:Test Demo
Test
考的是子类的实例化过程
3.写出程序结果
interface A{}
class B implements A
{
public String func()
{
return "func";
}
}
class Demo
{
public static void main(String[] args)
{
A a=new B();
System.out.println("a.func");
}
}
结果是:编译失败,因为A接口中并未定义func()方法。
4.写出程序结果
class Fu
{
boolean show(char a)
{
System.out.println(a);
return true;
}
}
class Demo extends Fu
{
public static void main(String[] args)
{
int i=0;
Fu f=new Demo();
Demo d=new Demo();
for(f.show('A');f.show('B')&&(i<2);f.show('c'))
{
i++;
d.show('D');
}
}
boolean show(char a)
{
System.out.println(a);
return false;
}
}
结果是:A
B
5.写出程序结果
interface A{}
class B