[go: up one dir, main page]

0% found this document useful (0 votes)
10 views6 pages

OODJ - Test 1 - QP

The document consists of a test with multiple-choice questions and descriptive questions related to Java programming concepts. It includes questions on associations between classes, code output predictions, exception handling, and inheritance. Additionally, it requires students to write Java code for creating an Employee class and identify mistakes in a given code snippet.

Uploaded by

exploitzeroday45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

OODJ - Test 1 - QP

The document consists of a test with multiple-choice questions and descriptive questions related to Java programming concepts. It includes questions on associations between classes, code output predictions, exception handling, and inheritance. Additionally, it requires students to write Java code for creating an Employee class and identify mistakes in a given code snippet.

Uploaded by

exploitzeroday45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

OODJ Test Page 1 of 6

SECTION A (10 MARKS)


MULTIPLE CHOICE QUESTIONS = ANSWER ALL QUESTION
(EACH QUESTION 1 MARK)

Q. Solve following questions


1. Give the type of Association that exists between Class 1 and Class 2

a) Association
b) Aggregation
c) Composition
d) Inheritance
e) None of the mentioned.

2. Identify the appropriate type of relationship among the use cases shown in below figure:

a) extends
b) generalization
c) includes
d) inheritance
e) polymorphism

Level 2 Asia Pacific University of Technology & Innovation 2023


OODJ Test Page 2 of 6

3. Identify the correct example of Composition type of Association among classes

a) Library and Books


b) Library and Students
c) Faculty and Students
d) Faculty and Staffs
e) Students and Books

4. What will be the output of the following code if 6,9,12,9,15 are the inputs?

a) 12 6 2 4 8 10 14 16 18 20
b) 12 2 4 8 10 14 16 18 20 6
c) 12 6 2 8 10 14 16 18 4 20
d) 12 10 14 16 18 20 6 2 20
e) 12 6 2 4 8 10 14 16 14 20

Level 2 Asia Pacific University of Technology & Innovation 2023


OODJ Test Page 3 of 6

5. What will be the output of the following code, if the input is 9001?

import java.util.*;
public class NewClass {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
System.out.println("Enter an integer: ");
int n = sc.nextInt();
System.out.println("Method APU: " + APU(n));
System.out.println("Method APIIT: " + APIIT(n));
System.out.println("Method APIS: " +
Integer.parseInt(APIS(n)));
}

public static int APU(int n) {


int sum = 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
return sum;
}

public static int APIIT(int n) {


int n1 = n;
while (n1 >= 10) {
n1 = 0;
while (n > 0) {
n1 += n % 10;
n /= 10;
}
n = n1;
}
return n1;
}
public static String APIS(int n) {
String s = new Integer(n).toString();
String s1 = "";
int len = s.length();
for (int i = 0; i < len; i++) {
s1 += s.substring(len - i - 1, len - i);
}
return s1;
}
}

Level 2 Asia Pacific University of Technology & Innovation 2023


OODJ Test Page 4 of 6

a)
Method APU: 10
Method APIIT: 1009
Method APIS: 1

b)
Method APU: 1
Method APIIT: 10
Method APIS: 1009
c)
Method APU: 10
Method APIIT: 1
Method APIS: 1009
d)
Method APU: 1009
Method APIIT: 1
Method APIS: 10

e)
None

6. In Java, a try block is followed by one or more ……………….. blocks.

a) Throw
b) Run
c) Exit
d) Catch
e) Error.

Level 2 Asia Pacific University of Technology & Innovation 2023


OODJ Test Page 5 of 6

7. Given the list of outputs, select the correct output produced by the following code:

public class OODJ{


public static void main(String[] args) {
int opt = 20, opt1 = 30;
if(opt == 30){
if(opt1 == 30) {
System.out.println(“Hi Hi Hi Hi Hi”);
}
else {
System.out.println(“Hello Hello Hello”);
}
}
System.out.println(“Bye Bye Bye”);

}
}

a) Hi Hi Hi Hi Hi
b) Hello Hello Hello
Bye Bye Bye
c) Bye Bye Bye
d) Hi Hi Hi Hi Hi
Hello Hello Hello
Bye Bye Bye
e) Hello Hello Hello

8. The keyword used to perform inheritance is:


a) implements
b) throws
c) extends
d) static
e) implements

9. A Constructor is explained as
a) method that must have the same name as the class it is declared within.
b) used to create objects.
c) method that can be declared private
d) both a) and b) above
e) a), b) and c) above.

Level 2 Asia Pacific University of Technology & Innovation 2023


OODJ Test Page 6 of 6

10. Superclass methods with this level of access cannot be called from subclasses.

a) private.
b) public.
c) protected.
d) package.
e) Abstract

SECTION B
DESCRIPTIVE QUESTIONS (15 MARKS)
ANSWER ALL QUESTION

B1. Write the Java code for applying the following requirement:

1. Create a class named Employee.


2. Employee has a name, age, and height. Add these to the Employee class.
3. Create a method that runs each time the class being instantiated. The method prompts the
user to enter required information (in step 2 of this question).
4. Create a method that prints the Employee Age whenever it is being called.
5. Create a class named Admin which is a sub-class of Employee.

(Total: 10 marks)

B2. Given the following snippet of Java code, Find the Five mistakes and correct them.

int inputValue;

System.println("Please, Enter an integer value: ");

inputValue = intInput.nextInteger();

if ( InputValue > 10)

System.out.println("The Value " & inputValue & " is Greater than 10.");

(Total: 5 marks)

Level 2 Asia Pacific University of Technology & Innovation 2023

You might also like