. (30 pts) : Answer yes or no by placing a 0 (true) or x (false) in your answer sheet.

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

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

93 εμφανίσεις



Java Programming 1/13 2003


Final Examination

I
. (30 pts)
是非題

䅮Awer⁹ 猠潲漠o礠y污捩l朠愠
0

⡴rue⤠)r
x

⡦慬獥a⁩n
祯yr

慮獷er⁳ ee琮

1.

A
class containing only private const
ructors is useless since there is no way to create its instances.

2.

Users can define their own subclasses of Exception
. .

3.

An object’s type cannot change at runtime.

4.

Private variables of an outer class are not accessible from any method of its inner classes

5.

I
nstance methods can use simple name to refer to all static variables of the containing class.

6.

A
bstract

class must contain at least one abstract method.

7.

Garbage collection may cause a reference to become
null
unexpectedly
.

8.

The expression

null instanceof Ob
ject


would be evaluated to

true

.

9.

In java we are allowed to
declare

two local
variables

of the same name: one in an outer block and
the other in a nested block of the outer block.

10.

A
n interface
may extend more than one
interfaces
.

11.

If interface A extends i
nterface B and C is a concrete class implementing A, then A must also
implement all methods declared in B.

12.

If
A

is a subclass of
B

then
A[
] is a subtype of
B[]
.

13.

Both
Object[]

and
int[]

are subtypes of
Objec
t.

14.

If A is a class with a
public

method
m()
, we ca
n overwrite
m()

with a new
protected

m()

in a
subclass of A.

15.

A class
must have at least one constructor even if it is abstract.


II
(110 pts)

選擇與簡答

⠠湯瑥㨠
選擇部分
ㄬ㈬1
為單選

)

1.


(5 pts) Suppose class A extends class B, class B extends class D, and all classes d
eclare a public
field f. In order to refer to the field f declared at class D within class A, Which of the following
expressions can be used :

(a)

super.super.f,

(b) (D) f


(c) super.f


(d) f


(e) D.super.f

2.

(5 pts) Suppose class A extends class B, class
B extends class D, and all classes declare a public
field
m()
. In order to refer to the method m() declared at class D within class A, Which of the
following expressions can be used :

(a)

super.super.m()

(b) (D) m()

(c) super.m()

(d) D.super.m()


(e)

none

3.

(5 pts) Which of the following are legal Java identifiers?

(a)

my
-
book (b) 1stName (c) $reserved (d) implement (e)
變數
1

4.

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

(a)

OutOfMemeoryError (b)ArithmeticExcepti
on (c) NullPointerException

(d) ArrayIndexOutOofBoundsException

(e)
ClassNotFoundException


5.


(5 pts) Choose the types whose values can be stored in a java,util.Vector object.

(a)

Integer

(b) float

(c) Double

(d) String

(e) char

6.

(5 pts)
Which

of the follow
ing classes are containers in Java swing GUI ?

(a)

J
Frame

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

7.

(10 pts) An interface without any member declarations is called a marker interface.

(a)

List two marker interfaces defined in the standard java p
ackages.

(b)

Why do we need marker interface ? ____________________________________________

_________________________________________________________________________

8.

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

s standard packages:

(a)

S
et (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 final classes from the above lis
t. _________________________________________


___________________________________________________________________________

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 enter into the blocked state. ________________________

______________________________________________________
________________

10.

(8 pts)

(a)

Why should the method
hashCode()

also be redefined when we overwrite the method
equals(Object)

of the
Object

class in a subclass. _________________________

______________________________________________________________________

___
___________________________________________________________________

______________________________________________________________________

(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 built for you. __________________

_________________________________________________________
___________________

____________________________________________________________________________

____________________________________________________________________________

12.


(5 pts) List three implementations of the interface
java.util.List

and two implem
entations
of the interface
java.util.Map
.

13.

(8 pts) List all primitive types that Java provides.

14.

(12 pts )[Java IO]

(a)

Write a statement to open a file

file1.data


as an
ObjectInputStream

and assign
it the variable input1.

ObjectInputStream input1
= _________
___________.

(b)

Write a set of statements that read a student record from input1. Assume the records in
file1.data consists of string
name
, integer

age

and floating number
GPA
.

String name =

____________________;

int age =

__________________________;

float
gpa =

______________;


15.

[10 pts] Write a simple method to print out on the console the content of a web page the url string
of which is given as input..

public void dumpPage(String addr ) { // addr is an url like

http://yahoo.com/


URL url = _____________
__________ ;

__________________________________________________________________

___________________________________________________________________

___________________________________________________________________

_______________________________________
____________________________




}

16.

[10 pts] Write a simple method to sort an input int array ( in
ascending

order ):


public void sort(int[] a ) {

_________________________________________________________________________

_________________________________
________________________________________

_________________________________________________________________________

__________________________________________________________________________




}