Java Programming

estrapadesherbetΛογισμικό & κατασκευή λογ/κού

18 Νοε 2013 (πριν από 3 χρόνια και 11 μήνες)

84 εμφανίσεις



Java Programming 1/14 2002


Final Examination

I
.
(40 pts)
是非題

A湳w敲⁹ 猠潲漠 礠灬y捩湧n愠
0

(t牵攩爠
x

(fal獥)⁩渠
祯畲

慮aw敲
獨敥t.

1.

A constructor of class
C
cannot take
an argument of class
C
.

2.

A class may have at most one constructor.

3.

An object’s type cannot change at runtime.

4.

The constructor of a class cannot return objects of a subclass.

5.

A subclass may override but not eliminate methods.

6.

Interfaces can have construc
tors.

7.

A class may extend more than one class.

8.

Every object has a
hashCode
method.

9.

Primitive values may not be stored in arrays.

10.

null
can be regarded as an object of class
Object
.

11.

Some iterators allow elements to be removed during iteration.

12.

A call to

a method that throws a checked exception must appear in a
try
-
catch
.

13.

Garbage collection may cause a reference to become
null
unexpectedly
.

14.

Assigning null to an argument just before returning has no effect on callers of a

method.

15.

If
o
is null, the call
o.m(x)
must throw an exception.

16.

If the compiler admits the expression
o.m(x)
,
o
cannot be bound at runtime to an

object that does
not have method
m.

17.

Unchecked exceptions cannot be user
-
defined.

18.

A constructor cannot have side effects.

19.

Private variables of

an inner class cannot be accessed from any method of
the

containing class

20.

Static methods can refer to all instance variables of the containing class.

II
選擇與簡答

( note:
選擇部分僅
㘮‷⸠
為單選

)

1.

(5 pts) Which of the following identifiers are Java

s reserved words ?

(a) java (b) while (c) new (d) goto (e) implement

2.

(5 pts) Which of the following types are not Java

s primitive types:

(a)

int (b) Double (c) float (d) String (e) Long

3.

(5 pts) Choose from the following all types the values of which cannot be stored in an i
nstance of
the java.util.List interface.

(a)

Integer

(b) float

(c) Double

(d) String

(e) Character

4.

(5 pts) List five subclasses of the class
java.io.OutputStream




5.

(10 pts) The following is a list of classes / interfaces defined in Java

s standard packages:

(a)

Set (b) RunTime (c) String

(d) Hashtable (e) Iterator

(f) Error

(g) Vector

(h) Collections (i) Number

(j) DataInput


(A) List all interfaces from the above list

(B) List all abstract classes from the above list

(C) List all final classes from the ab
ove list

6.

(5 pts) Which of the following Throwable subclasses in java.lang package are checked Exception ?

(a)

OutOfMemeoryError (b)ArithmeticException (c) NullPointerException

(d) ArrayIndexOutofBoundsException

(e)
ClassNotFoundException

7.

(5pts) What value
would be printed out for the following
java program

segment:

int x = 5;

if(++x > 5) if (x
--
>5) {x = 2 * x; System.out.print(x)};

else { x
--
; System.out.print(x) };


else System.out.print(x);

(a)

5 (b) 10 (c) 8 (d) 6 (e) compile
-
time error

8.

(5 pts) List 3

items from the
following

list which are most frequently referred to as the main
features of an Object
-
Orient Programming language.

(a)

structured programming (b) multi
-
threading

(c) data abstraction

(d) inheritance



(e) polymorphism

(e) GUI

(h) network

programming support



(i) Exception

9.

(6 pts)

(a)

List all possible states of a Java thread.

(b)

List 3 non
-
deprecated methods defined in the
Thread

class [or its all superclasses] that
may cause a Java thread to leave the running state.

10.

(10 pts)

(a)

Explain why w
e need additional

equals


methods even though Java has provided a basic

==


comparison operator in the language.

(b)

Give an example in which

x == y



and

x.equals(y)


has different truth values.

11.

(5 pts) List 5 kinds of Layouts that standard Java GUI has b
uilt for you.

12.

(5 pts)
Which

of the following classes are containers in Java swing GUI ?

(a)

J
Frame

(b) JLabel (c) JDialog (d) JPanel (e) JMenuItem (f) JTabbedPane

13.

(5 pts) Explain the difference between overriding a method and shadowing a variable that Java
use
d to handle duplicate
definitions

among subclasses and superclasses

14.

(4 pts) List an implementation of the interface
java.util.SortedSet

and an implementation
of the interface
java.util.SortedMap
.