Midterm Exam
Java Programming CS410x Show Work
Please write your name ( print please ):
Please write your Student ID#:
Fill in the blank with the correct answer:
1
. Object oriented questions
( 35 points)
a) If the class Alpha inherits from the class Beta, class Alpha is called the
child
dervied
sub
class and class Beta is called the
super
parent
base
class.
b) A method call resolved at run time is referred to as
late
dynumic
binding.
c) A method call resolved at compile type is referred to as
static
non-dynamic
binding.
d) A "has a" relationship between classes represents
nesting
composition
encapsulation
and an "is a" relationship represents
inheriting
.
e) An object of a
child
sub
derived
class can be treated as an object of its corresponding
parent
super
base
class.
f) If a class contains one or more abstract methods, it is an
abstract
class.
g) Three member access specifies are
protect
,
private
default
and
public
.
2
.
(5 points)
A java program file must end with the
java
file extension.
3
.
(5 points)
When a java program is compiled, the file produced by the compiler ands with the
class
file extension.
4
.
(5 points)
Identify and correct the errors in the following statement:
if ( c < 7 );
g.drawString(" c is less than 7", 25, 25);
answer:
if ( c < 7 )
5
. (5 points) What is wrong with the following
while
repetition structure:
while(z>=0)
sum += z;
answer:
it never ends
it will never break
6
.
(10 points)
For the following program, state the scope (either class scope or block scope) of each of the following elements.
a) the variable
x
.
class
b) the variable
y
.
block
c) the method
cube
.
class
d) the method
paint
.
class
e) the variable
yPos
.
block
Public class Cube Test extends Applet {
int;
public void point ( Graphics g ) {
int yPos = 25;
for (x =1; x <= 10; x++){
g.drawString(cube(x), 25, yPos);
yPos += 15;
}
}
public int cube (int y) {
return y * y * y;
}
}
7
.
(10 points)
Answer the following questions regarding an array called
fractions
.
a) Declare an array with
arraySize
elements of type
float
and initialize the elements to 0;
float fractions[ ] = new float [array size];
b) name the fourth element from the beginning of the array.
fractions[3]
c) Refer to array element 4.
fractions[4]
d) Assign the value 1.667 to array element 9.
fractions[9] = 1.667;
e) Sum all the element of the array using a for repetition structure. Define the integer variable x as a control variable for the loop.
float total = 0; for(int x=0; x<fractions.length; x++) total t =fractions[x];
8
.
(10 points)
Object based fill-in the blank questions:
a) Members of a class specified as
private
are accessible only to methods of the class.
b) The keyword
class
introduces the class_name.
c) The
new
operator dynamically allocates memory for an object of a specified type and return a
reference
to that type.
d) The keyword
static
public
before an instance variable makes it available to all instances of that class.
e) A method declared as static cannot assess
non-static
class members.
9
.
(15 points)
Fill in the blank
a) RGB is short for
red
,
green
and
bule
.
b) The return type of
getName
is
string
.
c) GUI is an acronym for
graphic user interface
.
if you have comments, add them in the following text box:
To send the information, click the Submit button.
To clear your entries and start over, click the Reset button.
Cover page
Last Update: 11/03/96
Copyright © 1996 - Douglas Lyon
Lyon@cse.bridgeport.edu