Question 1

batterycopperInternet and Web Development

Nov 12, 2013 (3 years and 9 months ago)

130 views

CSE 219


Spring 2013


Mi
dterm

Exam


Group A

1

CSE 219


Spring 2013


Mi
dterm

Exam


Group A

Mon
day,
3/25/2013

Name: First





Last







Student ID # _________________________________




Please show your ID when requested.



Please leave at least one seat between yourself and the person next to you
.



Use a #2 Pencil to fill in the appropriate bubble on your answer sheet.



Fill in one answer per question No books, notes, or electronic equipment can be used during the exam.



For all questions, select the
best

answer from the choices provided



Any CHEATI
NG will result in an F as well as being written
-
up on academic dishonesty.






FIRST:



Write and fill in the bubbles for your full name on the answer sheet



Write and fill in the bubbles for your ID Number on the answer sheet



DO NOT FILL IN YOUR DATE OF BIRT
H



Under the BIRTH DATE Table, go to the Left Column of DAY, you'll see only 4 choices (0
-
3). If
you have Exam Version A, fill in 0, if you have Exam Version B, fill in 1.



ATTENTION:

Make sure your exam has all 50

questions
.


CSE 219


Spring 2013


Mi
dterm

Exam


Group A

2

Question 1


In HW
3

we def
ined the
MiniGameDataModel

and
RegionPickerDataModel

classes. For the test
method defined below, which line below would result in a syntax error?



public

static

void

test(

RegionPickerDataModel

r,

MiniGameDataModel

m
)


{



r = m;




// A



m

= r;




//
B



Object obj1 =
m
;


//
C



Object obj2 =
r
;


//
D



obj1 = obj2;



//
E


}



Question 2

When extending Java’s
TimerTask

class, what method would you override in your class to define the work
done by the
thread

who executes the task
?

A)

init

B)

lock

C)

run

D)

schedule

E)

start



Question 3

What Java class did we use for securing access to data shared between

threads?

A)

Collection

B)

MediaTracker

C)

ReentrantLock

D)

Runnable

E)

ThreadScheduler



Question 4

The _________________ only cares about an object’s actual
type.

A)

Java Compiler

B)

Jav
a Virtual Machine (JVM)

C)

Subversion Client

D)

Thread Scheduler

E)

JDK



Question 5

The actual type of an object refers to the type the object was _______________ as
.

A)

Assigned

B)

Cast

C)

Constructed

D)

Declared

E)

Inherited

CSE 219


Spring 2013


Mi
dterm

Exam


Group A

3

Question 6

The _________________ only cares about an

object’s apparent
type.

A)

Java Compiler

B)

Java Virtual Machine (JVM)

C)

Java Runtime Environment (JRE)

D)

Thread Scheduler

E)

JDK


Question 7

The apparent type of an object refers to the type the object was _______________
_______________ as.

A)

Assigned

B)

Cast

C)

Constructed

D)

Declared

E)

Inherited


Question 8

In the MiniGameFramework, what Java keyword did we use in association with a try block to ensure code for
unlocking shared data is executed whether an error is thrown or not?

A)

catch

B)

finally

C)

null

D)

synchronize

E)

volatile


Question

9

What term is used to describe a group of cooperating classes and interfaces that together may be used to build
applications, providing that application with functionality for a particular technology as well as potential for
customization?

A)

Abstract Class
es

B)

Enumeration

C)

Framework

D)

Integrated

E)

JRE


Question 10

What term is used in Software Engineering to describe how well a program will perform when we
increase the size of the problem, i.e. the number of users or the amount of data processed
?

A)

Extensibility

B)

Fle
xibility

C)

Regression

D)

Robustness

E)

Scalability


Question 11

What term is used to describe the scenario where a lack of atomicity in a transaction in a multithreaded
environment can cause one thread to corrupt the work done by another thread?

A)

Daemon

B)

Deadlock

C)

Ra
ce Condition

D)

Volatility

E)

Zombie

CSE 219


Spring 2013


Mi
dterm

Exam


Group A

4

Question 12

In Hw
2

we validated input files against S
chemas. What was the file extension for these schemas
?

A)

.css

B)

.html

C)

.xhtml

D)

.xml

E)

.xsd


Question 13

Which one of the following statements below is true?

A)

An abstract class may

have a constructor.

B)

An abstract class may be constructed.

C)

An interface may have a constructor

D)

A variable may have an interface as its actual type

E)

A variable may have an abstract class as its actual type


Question 14

In
HW 2

we
saw

how Java provides a gene
ric
Map

type family, whose actual types manage different types of data
structures. What is one of these types of
Map

data structures?

A)

Acyclic Graph

B)

Binary Search Tree

C)

Doubly Linked List

D)

Heap

E)

Singly Linked List


Question 15

What did we say is a primary reas
on for using <generics>?

A)

Because all classes in Java are descendants of Object

B)

Because compiler errors are better than runtime errors

C)

Because all Collections framework classes like Vector are abstract

D)

Because eclipse requires it

E)

Because Java runs on a virt
ual machine, not in native code


Question 16

What term did we use to describe a program that anticipates erroneous user input before it happens and so is able
to handle such input intelligently, providing necessary feedback when necessary?

A)

Data
-
Driven

B)

Exte
nsible

C)

Modifiable

D)

Robust

E)

Top
-
Down


Question 1
7

What is used to call a constructor in a parent class during a child class’ construction?

A)

new

B)

super.

C)

super( )

D)

this.

E)

this( )

CSE 219


Spring 2013


Mi
dterm

Exam


Group A

5

Below are the definitions for the
Camera

and
Vec

classes which should be used to answe
r the questions that
follow:


public

class

Camera

{


public

Vec position = new Vec();


public

Vec lookAtVector = new Vec();


public Vec upVector = new Vec();


public Vec rightVector = new Vec();

}


public

class

Vec

{


public

int

x = 0;


public

int

y = 0;


public int z = 0;


public int zoom = 1;


public int index = 1;

}


Question 1
8

How many bytes would be allocated onto the heap
in total

when a
Camera

object is constructed

inside a method
and assigned to a local variable
?

A)

16

B)

80

C)

96

D)

128

E)

256



Question 19

How

many bytes would be allocated onto the call stack
in total

when the Camera class’ position instance variable
is constructed?

A)

0

B)

4

C)

8

D)

20

E)

40



Question 20

Which of the following constructs below cannot have a constructor?

A)

Abstract Classes

B)

Concrete Classes

C)

Int
erfaces

D)

All of the above

E)

None of the above

CSE 219


Spring 2013


Mi
dterm

Exam


Group A

6

The code

on the right

compiles and executes without error.

Note that there are 6 lines printed.



Question 21

When executed, what would the
1
st

l
ine of output be?

A)

0

B)

3

C)

6

D)

9

E)

10


Question 22

When executed, what woul
d the
2
nd

l
ine of output be?

A)

0

B)

3

C)

6

D)

9

E)

10


Question 23

When executed, what would the
3
rd

line of output be?

A)

0

B)

3

C)

6

D)

9

E)

10


Question 24

When executed, what would the
4
th

line of output be?

A)

0

B)

1

C)

3

D)

9

E)

10


Question 25

When executed, what would the
5
th

line of output
be?

A)

0

B)

1

C)

2

D)

3

E)

10


Question 26

When executed, what would the
6
th

line of output be?

A)

0

B)

1

C)

2

D)

3

E)

10




Camera c = new Camera();




Vec p = c.position;

p = new Vec();

p.x = 6; p.y = 5; p.z = 4;


Vec p2 = p;

p2.x = 9; p2.y = 8; p2.z = 7;




Vec lav = c.lookAtVector;

lav = new Vec();

lav.x = 3; lav.y = 2; lav.z = 1;




System.out.println(c.position.x);

System.out.println(p.x);

System.out.println(c.lookAtVector.x);

p2.x++;

System.out.println(p2.x);


Camera c2 = new Camera();

c2.position = c.lo
okAtVector;

c2.position.zoom = 2;

c2.position = new Vec();

c2.position.zoom++;


System.out.println(c.position.zoom);

System.out.println(c2.position.zoom);

CSE 219


Spring 2013


Mi
dterm

Exam


Group A

7

The code on the right compiles and executes without error. Note that there are
5

lines printed.



Question 27

When executed, what would the
1
st

line of output
be?

A)

0

B)

1

C)

3

D)

4

E)

6


Question 28

When executed, what would the
2
nd

line of output be?

A)

0

B)

1

C)

3

D)

4

E)

6


Question 29

When executed, what would the
3
rd

line of output be?

A)

0

B)

1

C)

3

D)

4

E)

7


Question 30

When executed, what would the
4
th

line of output be?

A)

0

B)

1

C)

3

D)

6

E)

7


Question 31

W
hen executed, what would the
5
th

line of output be?

A)

0

B)

1

C)

4

D)

6

E)

7


Question 32

Which of the following constructs below cannot be inherited?

A)

private instance variables

B)

protected instance variables

C)

public instance variables

D)

protected static variables

E)

All of the
above


public class Ref

{


public static void main(

String[] args)


{


Vec v = new Vec();


int a =

v.x;


a++;


int b = 3;


v.y = 5;


int c

= reset(v, v, a, b);


v.y++;


System.out.println(a);


System.out.println(b);


System.out.println(v.x);


System.out.println(v.y);


System.out.println(c);


}



public static int reset(

Vec v1, Vec v2, int x, int y)


{


v1 = new Vec();


v1.x = 4;


v2.y = 5;


x = 6;


y = 7;


return y;


}

}

CSE 219


Spring 2013


Mi
dterm

Exam


Group A

8

Question 33

What term is used to describe for a program providing an approximation of service when an error occurs?

A)

Abstraction

B)

Bootstrapping

C)

Debugging

D)

Graceful Degradation

E)

System Recovery


Question 34

When rendering inside a JPanel in Java, inside

what overridden JPanel method should rendering instructions be
placed?

A)

paintComponent

B)

redraw

C)

render

D)

repaint

E)

updateView


Question 35

What type of java structure is MouseListener?

A)

Abstract Class

B)

Concrete Class

C)

Enum

D)

Interface

E)

Iterator


Below are the class de
finitions for the
Account
,
EvilAccount
,
CrazyAccount
,
CraziestAccount
,
LaziestAccount
, and
AccountDriver

classes, which all compile and run without error.
Note these are
used for the questions on the following page.





























public

class

Account

{


public

int

balanc
e;




public

void

reset()


{



balance = 1;


}

}


public

class

EvilAccount
extends

Account

{


public

void

reset()


{



balance = 2;


}

}


public

class

CrazyAccount
extends

EvilAccount

{


public

void

reset()


{



balance = 3;


}

}


public

class

CraziestAccount
extends

CrazyAccount


{


public void reset() { balance = 4; }


}


public

class

L
aziestAccount
extends

CraziestAccount

{ }


CSE 219


Spring 2013


Mi
dterm

Exam


Group A

9

The co
de below compiles and executes without error. Note that there are 4 lines printed.






















Question
36

When executed, what would the 1
st

line of output be?

A)

0

B)

1

C)

2

D)

3

E)

4


Question
37

When executed, what would the 2
nd

line of output be?

A)

0

B)

1

C)

2

D)

3

E)

4


Question
38

When executed, what would the 3
rd

line of output be?

A)

0

B)

1

C)

2

D)

3

E)

4


Question 3
9

When executed, what would the 4
th

line of output be?

A)

0

B)

1

C)

2

D)

3

F)

4


public

class

AccountDriver

{


public

static

void

main(String[] args)


{



EvilAccount ea =
new

EvilAccount();



foo
(ea);



CrazyAccount ca =
new

CrazyAccount();



foo
(ca);



CraziestAccount ca2 =
new

CraziestAcc
ount();



foo
(ca2);



LaziestAccount la =
new

LaziestAccount();



foo
(la);


}




public

static

void

foo(Account acc)


{



acc.reset();



System.
out
.println(acc.balance);


}

}


CSE 219


Spring 2013


Mi
dterm

Exam


Group A

1
0

Question
40

The
AppVsAct

program below does not compile.
Which line number would the compiler flag?

A)

6

B)

7

C)

14

D)

15

E)

16


Question 4
1

For the
AppVsAct

program, should we comment out the line of code you flagged in the previous question, it will
compile and run, but a runtime error will occur. Which line of code would be the source of the runtime error?

A)

6

B)

7

C)

14

D)

15

E)

16


Question 4
2

For your answer from the previous question, what type of exception would occur?

A)

ArithmeticException

B)

ClassCastException

C)

IndexOutOfBoundsException

D)

NullPointerException

E)

OutOfMemoryException









public class AppVsAct

{ // 1


public static void main(Stri
ng[] args) {

// 2



String st = "Hello";




// 3



Object ob = st;





// 4



fooA(ob);





// 5



fooA(st);





// 6



fooB(ob);





// 7



fooB(st);





// 8


}







// 9









// 10


public static void fooA(Object obj){ // 11



String s = (S
tring)obj;


// 12



char c = s.charAt(0);



// 13



obj = s;





// 14


obj = new Object();

// 15


s = (String)obj;

// 16



System.out.println(obj);


// 17


}







// 18









// 19


public s
tatic void fo
oB(String str){
// 20



char c = str.charAt(0);


// 21



System.out.println(c);


// 22


}







// 23

}

// 24


CSE 219


Spring 2013


Mi
dterm

Exam


Group A

1
1

The code below compiles and executes without
error. Note that there are 4 lines printed.



Question 4
3

What would the 1
st

line of output be?

A)

Car

B)

Jeep

C)

SUV

D)

Vehicle

E)

None of the above


Question 4
4

What would the 2
nd

line of output be?


A)

Car

B)

Jeep

C)

SUV

D)

Vehicle

E)

None of the above


Question 4
5

What would the 3
rd

line of output be?


A)

Car

B)

Jeep

C)

SUV

D)

Vehicle

E)

None of the above


Question 4
6

What would the 4
th

line of output be?


A)

Car

B)

Jeep

C)

SUV

D)

Vehicle

E)

None of the above












public

class

Driver {


public

static

void

main(String[] args) {


for

(
int

i = 1; i <= 4; i++)


{


Vehicle v =
makeVehicle
(i);


driveVehicle
(v);


}


}




public

static

void


driveVehicle(Vehicle v) {



v.drive();


}




public

static

Vehicle

makeVehicle(
int

type) {


if

(type == 1)


return

new

Vehicle();


else

if

(type == 2)

return

new

Car();



else

if

(type == 3)

return

new

SUV();


else




return

new

Jeep();



}

}


class

Vehicle {


public

void

drive() {


System.
out
.println("Vehicle");


}

}


class

Car
extends

Vehicle {


public void drive() {


System.out.println("Car");


}

}


class

SUV
e
xtends

Car {}


class

Jeep
extends

SUV {


public

void

drive() {



super
.drive();


}

}


CSE 219


Spring 2013


Mi
dterm

Exam


Group A

1
2

Question 4
7

What word is used in software development to describe how capable a solution is

to accommodate adding on to
its functionality?

A)

Efficiency

B)

Extensibility

C)

Reliability

D)

Scalability

E)

Usability


Question 4
8

What can be found in both an abstract class and an interface?

A)

abstract methods

B)

concrete methods

C)

inner class

D)

instance variables

E)

static va
riables


Question 4
9

W
hich of the following statements below is false?

A)

A static method may directly reference (without a ‘.’) a static variable from the same class.

B)

A non
-
static method may directly reference a static variable from the same class.

C)

A static
method may directly reference a non
-
static variable from the same class.

D)

A non
-
static method may directly reference a static method from the same class.

E)

A non
-
static method may directly reference a static constant from the same class.


Question 50

What doe
s the “M” in XML stand for?

A)

Mana

B)

Markup

C)

Meta

D)

Modern

E)

Motif