黑马程序员_JAVA基础联系题

------- android培训java培训、期待与您交流! ----------

1.

public class Joker {

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) {

// TODO: handle exception

System.out.println("C");

}

System.out.println("D");

}

}

//编译失败。因为func抛出了异常而函数上没有申明。

如果func()上抛出了Exception 结果会是BCD。

2.public class Joker extends Test{

Joker() {

super();

System.out.println("Joker");

}

public static void main(String[] args) {

new Joker();

new Test();

}

}

class Test {

Test() {

System.out.println("Test");

}

}

结果是Test,Joker,Test(这题考察的是子类的实例化过程)

3.public class Joker{

public static void main(String[] args) {

A a = new B();

System.out.println(a.func());

}

}

interface A{}

class B implements A {

public String func() {

return "func";

}

}

结果是:编译失败。父类中并没有定义func()方法。

4.

public class Joker extends Fu{

public static void main(String[] args) {

int i = 0;

Fu f = new Joker();

Joker j = new Joker();

for(f.show('A');f.show('B')&&(i < 2);f.show('C')) {

i++;

j.show('D');

}

}

boolean show(char a) {

System.out.println(a);

return false;

}

}

class Fu {

boolean show(char a) {

System.out.println(a);

return true;

}

}

结果为:A.B因为在for里面第一次判断show()的时候由于子类重写了了父类的方法返回false了。所以退出了for循环。

5.

public class Joker extends Fu{

public static void main(String[] args) {

A a = get();

System.out.print(a.test());

}

static A get() {

return new B();

}

}

interface A {}

class B implements A {

public String test() {

return "yes";

}

}//编译失败。

6.

public class Joker extends Super{

public static void main(String[] args) {

int i = 4;

Super d = new Joker("A");

System.out.println(d.i);

}

public Joker(String a) {

System.out.println("C");

i = 5;

}

}

class Super {

int i = 0;

public Super(String a) {

System.out.println("A");

i = 1;

}

public Super() {

System.out.println("B");

i+=2;

}

}//结果为B C 5S执行uper d = new Joker("A");的时候会读Joker父类的构造函数Super();

7.public class Joker{

public static void main(String[] args) {

//补足代码;调用两个函数,要求用匿名内部类.

}

}

interface Inter {

void show(int a ,int b);

void func();

}

答案:

public class Joker{

public static void main(String[] args) {

//补足代码;调用两个函数,要求用匿名内部类.

Inter ii = new Inter() {

public void show(int a,int b) {

}

public void func() {

}

};

ii.show(0, 0);

ii.func();

}

}

interface Inter {

void show(int a ,int b);

void func();

}

8.

public class Joker{

public static String output="";

public static void foo(int i) {

try {

if(i == 1) {

throw new Exception();

}

output += "1";

}catch (Exception e) {

// TODO: handle exception

output += "2";

return;

}finally {

output+="3";

}

output+="4";

}

public static void main(String args[]) {

foo(0);

System.out.println(output);

foo(1);

System.out.println(output);

}

}//结果为123  13423

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
java程序设计》课程的库资料,由贺州学院整理,可供学生期末课程复习使用,也可以供相关任课教师出卷使用。 内容示例为: 40. __________包包含了Collection的接口的类的API。 答案:Java.util 41. Math.round(11.5)等于__________,Math.round(-11.5)等于__________。 答案:12; -11 [考点范围] 常用的系统类 42. ________对象可以使用read方法从标准的输入设备(通常键盘)读取数据;__________对象可以使用print方法向标准输出设备(屏幕)输出显示。 答案:System.in ;System.out [考点范围] JAVA输入输出系统 43. 框架(JFrame)和面板(JPanel)的默认布局管理器分别是______和_______。 答案:BorderLayout FlowLayout [考点范围] 图形用户界面 44. Swing的布局管理器主要包括_______。 答案:FlowLayout、BorderLayout、CardLayout、GridLayout、GridBogLayout、BoxLayout [考点范围] 图形用户界面 45. Java事件处理包括建立事件源、________和将事件源注册到监听器 。 答案:声明监听器 [考点范围] 图形用户界面 46. AWT的事件处理机制包括_______、事件和事件监听者。 答案:事件源 [考点范围] 图形用户界面 47. Swing的顶层容器有________、JApplet、JWwindow和JDialog。 答案:JFrame [考点范围] 图形用户界面 48. 线程的启动是通过调用其______________方法而实现的。 答案:start() [考点范围] 线程 49. Java虚拟机(JVM)中的线程调度器负责管理线程,调度器把线程的优先级分为10个级别,分别用Thread类中的类常量表示,每个Java线程的优先级都在常数________和_______之间,即Thread.MIN_PRIORIY和Thread.MAX_PRIORIY之间。 答案:1;10 [考点范围] 线程
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值