龙空技术网

JAVAEE面向对象封装继承多态期末复习题

JAVA架构前端技术 12

前言:

此时同学们对“javaee框架期末考试题及答案”都比较关怀,姐妹们都想要学习一些“javaee框架期末考试题及答案”的相关内容。那么小编同时在网上汇集了一些有关“javaee框架期末考试题及答案””的相关文章,希望你们能喜欢,朋友们快快来了解一下吧!

进度跟到异常的同学做,未跟上进度的不做(请尽快补课)

选择题

class Test {

public static void main(String[] args) {

String foo = args[1];

String bar = args[2];

String baz = args[3];

}

}

d:\>java Test Red Green Blue

what is the value of baz?

A. baz has value of ""

B. baz has value of null

C. baz has value of "Red"

D. baz has value of "Blue"

E. baz has value of "Green"

F. the code does not compile

G. the program throw an exception

接口选择题:

1)下面关于接口的说法中不正确的是(A C)。

A.接口中所有的方法都是抽象的

B.接口中所有的方法都是public访问权限

C.子接口继承父接口所用的关键字是implements

D.接口是Java中的特殊类,包含常量和抽象方法

2)Java语言接口间的继承关系是( )。一个接口可以继承多个接口。

A.单继承 B.多重继承 C.不能继承 D.不一定

3)一个类实现接口的情况是(A)。

A.一次可以实现多个接口 B.一次只能实现一个接口

C.不能实现接口 D.不一定

填空题

1)_____是声明接口的关键字,可以把它看成一个特殊类。接口中的数据成员默认的修饰符是_____,接口中的成员方法默认的修饰符是_____。

2)实现接口的实现类,必须重写接口中的所有________方法。

abstract class 和interface 有什么区别?

从构造方法、成员变量、成员方法来区别;

再从子类、实现类做区别; 答案比较完善;

是否能通过编译?

interface A{

int x = 0;

}

class B{

int x =1;

}

class C extends B implements A {

public void pX(){

System.out.println(x); //super.x A.x

}

public static void main(String[] args) {

new C().pX();

}

}

不可以,x有冲突;

Reference to 'x' is ambiguous, both 'B.x' and 'A.x' match

写出程序结果

interface A{}

class B implements A{

public String func(){

return "func";

}

}

public class Demo{

public static void main(String[] args){

A a=new B();

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

}

}

不能编译;

是否有误?

是否可以通过编译?

abstract class Something {

private abstract String doSomething ();

}

是否可以从一个static方法内部发出对非static方法的调用?编译是否通过?

public class Something {

public static void main(String[] args) {

Something s = new Something();

System.out.println("s.doSomething() returns " + doSomething());

}

public String doSomething() {

return "Do something ...";

}

}

静态方法调用实例方法的时候,需要声明实例,然后格式是实例.方法名;

方法前面有static关键字,调用格式可以类名.方法名,也可以是实例.方法名。

谈谈final, finally, finalize的区别(面试)

final:用来修饰常量(成员变量),需要被赋值,不可重复赋值。

final用来修饰方法,如果有子类继承自该来,则子类不能够重写被final修饰的方法。

finally:用来在try块里面。try+finally,也可以try+catch+finally格式;

finalize:?Object类中有finalize()方法,用来清理垃圾,垃圾回收期。

public class Something {

public int addOne(final int x) {

return ++x;

}

}

如下程序是否可通过编译?

public class Something {

public static void main(String[] args) {

Other o = new Other();

new Something().addOne(o);

}

public void addOne(final Other o) {

o.i++;

}

}

class Other {

public int i;

}

是否可以通过编译?

class Something {

int i; //成员变量 ,有默认初始值;为0

public void doSomething() {

System.out.println("i = " + i);

}

}

是否可以通过编译?

接上题

class Something {

final int i;

public void doSomething() {

System.out.println("i = " + i);

}

}

以下代码的运行结果是?

public class Test {

static int x, y, z;

static {

int x = 5;

x--;

}

static {

x--;

}

public static void main(String[] args) {

System.out.println("x=" + x);

}

}

标签: #javaee框架期末考试题及答案