0% found this document useful (0 votes)
75 views

2008 April Question Paper

This document contains 5 questions about object-oriented programming concepts in Java. It includes questions about inheritance, interfaces, operators, classes, methods, loops, and Strings. The questions cover defining and using classes, writing constructors and methods, performing calculations, iterating with loops, and working with Strings.

Uploaded by

Mukesh Regmi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

2008 April Question Paper

This document contains 5 questions about object-oriented programming concepts in Java. It includes questions about inheritance, interfaces, operators, classes, methods, loops, and Strings. The questions cover defining and using classes, writing constructors and methods, performing calculations, iterating with loops, and working with Strings.

Uploaded by

Mukesh Regmi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

STRICTLY CONFIDENTIAL

C2005 – April 2008 – QP

Question 1 (Compulsory) [30 marks]

(a) State which object oriented feature ensures code security, and describe two features
found in it. [3]

(b) Give two components of interface. [2]

(c) State the output for the below expression. [5]

(i) 16 % 5

(ii) 35 & 12

(ii) 2 << 3

(iv) 17 | 16

(v) 65 >> 2

(d) (i) Which keywords in java implements inheritance? [2]

(ii) What is the keyword used to activate super class method? [1]

(e) (i) Declare a class Oil which contains data members vendor of string type, and price
of double type. [2]

(ii) Implement a constructor to initialize all the attributes of Oil object. [2]

(iii) Implement a method overPrice which will return 4 for price above 100,
otherwise return 1. [2]

(iv) Write java codes to activate method overPrice using object bp of Oil category.
[3]

Please turn over

Page 1 of 5
STRICTLY CONFIDENTIAL
C2005 – April 2008 – QP

(f) Write a method diff with two parameters of double types. It returns the positive
difference of two values. [3]

(g) Write a method count which receives a parameter of an array search of integer data type.
It will return the total number of values greater than 40 found inside the data array. [5]

Please turn over

Page 2 of 5
STRICTLY CONFIDENTIAL
C2005 – April 2008 – QP

Question 2 [15 marks]

(a) Create a class Taxi that includes two attributes, price and seats, of type double and
integer respectively. [3]

(b) Write one public constructor setting the price attribute to 3.50. [2]

(c) Write method getPayment which returns the payments done by the payer where
payment is derived from number of seats multiplied by 3.50. [2]

(d) Write a changePrice method which will return true if the seat is above 10 and increase
the price by another 20% otherwise it will return false. [4]

(e) Write a main program to create object trip of Taxi type. It will activate all the methods
defined in the class. [4]

Question 3 [15 marks]

(a) Define a class called Account which includes a String member called id, and another
member called balance of double type. [3]

(b) Override the default constructor that will initialize the Account object. [3]

(c) Declare an array money that can stored up to 300 accounts. [2]

(d) Write a member method checkbalance that will display any account id that comes with
balance below 3000. [3]

(e) Write a member method called lowestbal. This method should search for and return
smallest balance in the money system. [4]

Please turn over

Page 3 of 5
STRICTLY CONFIDENTIAL
C2005 – April 2008 – QP

Question 4 [15 marks]

(a) Write a code segment to display outputs as stated below by using a while loop. [7]
No
16
12
8
4
Total = 40

(b) Rewrite the part (a) by using for loop. [5]

(c) State any type of loop that can be used to implement iteration. [1]

(d) Besides Java, state any other two object oriented programming languages. [2]

Please turn over

Page 4 of 5
STRICTLY CONFIDENTIAL
C2005 – April 2008 – QP

Question 5 [15 marks]

(a) Briefly explain what is String. [2]

(b) Explain any three methods found in String class. Do not mention the methods already
used in part (c). [3]

(c) State the output of the following codes. [10]

public static void main(String args[])


{
String data = “manchester united”;
int x = data.length();
char y = data.charAt(x%5)+ 2;
System.out.println(x);
System.out.println(y);
System.out.println(x+y);
System.out.println(data.equals(“Manchester united”));
System.out.println(X%7);
}

- END OF PAPER -

Page 5 of 5

You might also like