BIT 2204 OBJECT ORIENTED PROGRAMMING II KCA Past Paper

UNIVERSITY EXAMINATIONS: 2011/2012
SECOND YEAR EXAMINATION FOR THE BACHELOR OF
SCIENCE IN INFORMATION TECHNOLOGY
BIT 2204 OBJECT ORIENTED PROGRAMMING II
DATE: AUGUST, 2012 TIME: 2 HOURS
INSTRUCTIONS: Answer Question ONE and any other TWO

QUESTION ONE
a) Differentiate between Applet and Application as used in Java programming
(4 Marks)
b) List Four reason that explain why Java programming is popular (4 Marks)
c) JVM is an imaginary machine that is implemented by emulating it in software on
a real machine. Code for the JVM is stored in .class file extension, each of which
contains code for at most one public class.Describe FOUR tools that JVM
implements (8 Marks)
d) Differentiate the functional differences between Bycode verifier and the class
loader as used in Java programming (4 Marks)
e) When an object is created, instance variables are initialized with their respective
default values. What are the default values for the following instance types?
i. Byte
ii. Int
iii. Float
iv. Char
(4 Marks)
f) With examples Differentiate between type promotion and type casting (4 Marks)
g) Give the output of the above program
class RelationalOpSample {
public static void main ( String args[] ) {
int num1 = 10, num2 = 30;
System.out.println( num1 + “==” + num2 + ” = ” + ( num1== num2));
System.out.println( num1 + “!=” + num2 + ” = ” + ( num1!= num2));
System.out.println( num1 + “>=” + num2 + ” = ” + ( num1>= num2));
System.out.println( num1 + “<=” + num2 + ” = ” + ( num1<= num2));
}
}
(2 Marks)
QUESTION TWO
a) Predict the output of the following program

import java.io.*;
class InputSample1 {
public static void main ( String args[] ) throws IOException {
BufferedReader br = new BufferedReader(
new InputStreamReader( System.in));
String str;
int i=0;
int sum = 7;
System.out.println(“Current Total = ” + sum );
System.out.print(“Enter a number : “);
str = br.readLine();
try {
i = Integer.parseInt(str); // convert from String to integer
} catch ( NumberFormatException e ) {
System.out.println(“invalid format”);
}
sum = sum + i;
System.out.println(“\nNew Total = ” + sum);
}
(4 Marks)
b) Describe with examples the syntax of the following program flow controls and
advice when to use them
i. While
ii. Do while
iii. Endless/finite for control construct
(9 Marks)
c) Describe the following flow stubs
i. Continue
ii. Break
iii. Label
(6 Marks)
d) Give two rules used form naming variables (1 Mark)
QUESTION THREE
a) What is the relevance of the following keywords as used Java Programming?
Give examples to support your answer.
i. new
ii. extends
iii. implements
iv. throws
(8 Marks)
b) Create a class named Sweets. Its main() method holds an integer variable named
numberofSweets to which you will assign a value. Create a method to which you
pass numberofSweets. The method displays the sweets in dozens. For example, 40
sweets is 3 dozens and 4 left over. (6 Marks)
c) Create a class named Shirt with data fields for collar size and sleeve length.
Include a constructor that takes arguments for each field. Also include a String
class variable named material and initialize it to “cotton”. Write a program
TestShirt to instantiate 3 Shirt objects with different collar sizes and sleeve
lengths, and then display all the data, including material, for each shirt. (6 Marks)
QUESTION FOUR
a) Copy and complete the following table about access modifiers (The first one has
been done as an example) (6 Marks)

b) Interfaces are quite useful in programming (Java). Explain Four uses of interfaces
(4 Marks)
c) Explain the meaning of the following keywords
i. Final
ii. Instanceof
(4 Marks)
QUESTION FIVE
a) Create a class named Student. A Student has fields for an ID number, number of
credit hours earned, and number of points earned. (For example, many schools
compute grade point averages based on a scale of 4, so a three-credit-hour class in
which a student earns an A is worth 12 points.) Include methods to assign values
to all fields. A Student also has a field for grade point average. Include a method
to compute the grade point average field by dividing points by credit hours
earned. Write methods to display the values in each Student field.
b) Write a class named ShowStudent that instantiates a Student object from the class
you created. Compute the Student grade point average, and then display all the
values associated with the Student.
a) Create a constructor method for the Student class you created. The constructor
should initialize each Student’s ID number to 9999 and his or her grade point
average to 4.0. Write a program that demonstrates that the constructor works by
instantiating an object and displaying the initial values.
(20 Marks)

(Visited 91 times, 1 visits today)
Share this:

Written by