Get premium membership and access revision papers, questions with answers as well as video lessons.

Object Oriented Programming Ii Question Paper

Object Oriented Programming Ii 

Course:Bachelor Of Science In Information Technology

Institution: Masinde Muliro University Of Science And Technology question papers

Exam Year:2010



SECOND YEAR EXAMINATION FOR THE DEGREE OF BACHELOR OF
SCIENCE IN INFORMATION TECHNOLOGY
OBJECT ORIENTED PROGRAMMING II
DATE: APRIL 2010 TIME: 2 HOURS
INSTRUCTIONS: Answer Question ONE and any other TWO questions
QUESTION ONE
a) Java programming language is multithreaded. Explain the term and how it’s implemented
(3 Marks)
b) The absence of pointers prevents illegal access to memory. Java code passes several tests before actually executing on your machine. Bytecode verifier checks for illegal code. Java also prevents access to the local file system. All these are meant to improve security. List four passes that a Java program goes through before it can be passed to execute. (4 Marks)
c) List four goal of Java programming Language (4 Marks)
d) Define what you understand by JVM and what its relevance in Java Programming is (4 Marks)
e) Give the structure of a Java program (4 Marks)
f) What are the conventions for the following in Object Oriented Programming?
i. Classes
ii. Variables
iii. Constants
iv. Methods
v. Interfaces (5 Marks)
g) When an object is created, instance variables are initialized to particular values. Fill the
following table indicating the value initialized to these types
Data Type Value Data Type Value
Byte Float
Short Double
Int Char
Long boolean
(4 Marks)
What is the output of the following 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) Explain the difference between static and non-static member of a class (2 Marks)
b) Define inner class in Java (2 Marks)
c) What is the relevance of the following keywords?
i). this
ii). instanceof
iii). Applet (6 Marks)
d) Create a class named Monogram. Its main() method holds three character variables that hold your first, middle, and last initials, respectively. Create a method to which you pass the initials and which displays the initials twice—once in the order first, middle, last, and a second time in traditional monogram style (first, last, middle). (6 Marks)
e) When does a name clash occur? (2 Marks)
f) Briefly state the difference between static and dynamic modeling (2 Marks)
QUESTION THREE
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 FOUR
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 FIVE
a) Does garbage collection guarantee that a program will not run out of memory? Support your
answer (3 Marks)
b) 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.
(6 Marks)
c) 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. (4 Marks)
d) 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.(6 Marks)
e) Define the term scope (1 Mark)






More Question Papers


Popular Exams


Mid Term Exams

End Term 1 Exams

End Term 3 Exams

Opener Exams

Full Set Exams



Return to Question Papers