0% found this document useful (0 votes)
5 views11 pages

Java p2

The document is a sample final exam for an Object Oriented Development course at Asia Pacific University, containing descriptive questions and multiple-choice questions related to Java programming. It includes tasks such as writing a Java program based on a class diagram, analyzing code for errors, and answering questions about Java concepts and syntax. The exam covers various topics including access modifiers, inheritance, and variable declarations.

Uploaded by

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

Java p2

The document is a sample final exam for an Object Oriented Development course at Asia Pacific University, containing descriptive questions and multiple-choice questions related to Java programming. It includes tasks such as writing a Java program based on a class diagram, analyzing code for errors, and answering questions about Java concepts and syntax. The exam covers various topics including access modifiers, inheritance, and variable declarations.

Uploaded by

proseacharya07
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

lOMoARcPSD|49629040

Past Year Exsm Sample #1 (with answers)

Object Oriented Development With Java (Asia Pacific University of Technology and
Innovation)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Prashant Acharya (prashantacharya436@[Link])
lOMoARcPSD|49629040

CT038-3-2-OODJ Final Exam Page 1 of 10

SECTION A: DESCRIPTIVE QUESTIONS (25 MARKS)


ANSWER ALL QUESTION
QUESTION 1.

Given:

Figure 1.0

Please write a full Java program with the class diagram above (Figure 1.0):
Requirement:
1. Implement the Resizable interface that you have completed using Figure 1.0.
2. Provide constructor for the concrete classes.
3. Implement encapsulation concept.
4. The formulas to calculate area for square and cube are length*length and length*length*6
5. increase: length + size ; decrease: length – size
(15 marks)

[15 marks]
Suggested Solution:

Level 2 Asia Pacific University of Technology & Innovation 2024


Downloaded by Prashant Acharya (prashantacharya436@[Link])
lOMoARcPSD|49629040

CT038-3-2-OODJ Final Exam Page 2 of 10

Level 2 Asia Pacific University of Technology & Innovation 2024


Downloaded by Prashant Acharya (prashantacharya436@[Link])
lOMoARcPSD|49629040

CT038-3-2-OODJ Final Exam Page 3 of 10

QUESTION 2. Analyze following code. Assume output to be displayed is 5.5. Identify the mistake(s) in
the classes given below. (10
Marks)
You are required to write line number of error and correct code statement as your answer.

(for eg :- Line 25: [Link](“Thank you”);)

Sample Answer :
Line 3 : A a = new A(5.5);
Line 4
: Syste [Link](a.val_x())
;
Line 9: private double x;
Line 11: A(double val_x) {
Line 14: double val_x()

Level 2 Asia Pacific University of Technology & Innovation 2024


Downloaded by Prashant Acharya (prashantacharya436@[Link])
lOMoARcPSD|49629040

CT038-3-2-OODJ Final Exam Page 4 of 10

SECTION B: (20 MARKS)


MULTIPLE CHOICE QUESTIONS - ANSWER ALL QUESTION
(EACH QUESTION 1 MARK)
Q1. WHICH OF THE FOLLOWING IS TRUE ABOUT PROTECTED ACCESS MODIFIER?
A. Variables, methods and constructors which are declared protected can be accessed by any
class.
B. Variables, methods and constructors which are declared protected can be accessed by any
class lying in same package.
C. Variables, methods and constructors which are declared protected in the superclass can be
accessed only by its child class.
D. None of the mentioned
ANSWER: B

Q2. Which of the following is wrong about the differences between Java and C language?
A. Java supports pointer; C doesn’t support pointer
B. Java doesn’t use pre-processor; C uses pre-processor such as #define, #include, etc.
C. Java manages the memory using garbage collector; C uses malloc() and free() methods to
manage memory.
D. Java is platform independent; C is platform dependent.
ANSWER: C

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

A. Association
B. Aggregation
C. Composition
D. None of the mentioned

ANSWER: B

Q4. Which of the following is suitable for the code below?

A) public
B) private
C) protected
D) static
ANSWER: D

Level 2 Asia Pacific University of Technology & Innovation 2024


Downloaded by Prashant Acharya (prashantacharya436@[Link])
lOMoARcPSD|49629040

CT038-3-2-OODJ Final Exam Page 5 of 10

Q5. What is the result of the following program?

A. 5, 6, 7
B. 8, 6, 9
C. 8, 4, 9
D. 8, 4, 7
ANSWER: D

Q6. What is the result of the following expression if x=6 and y=8?

A. 112
B. 114
C. 102
D. 122
ANSWER: A

Level 2 Asia Pacific University of Technology & Innovation 2024


Downloaded by Prashant Acharya (prashantacharya436@[Link])
lOMoARcPSD|49629040

CT038-3-2-OODJ Final Exam Page 6 of 10

Q7. Which of the following lines will compile without warning or error if a=2, b=5, and c=true?

I. if(a,b) {}
II. if(c) {}
III. if(a==(b=2) {}
IV. if(a!= (b=10) {}

A. I only
B. I and II only
C. I, III, and IV only
D. All of the mentioned
ANSWER: D

Q8. Which access modifier makes a member available only to classes within the same package and sub
classes?
A. public
B. private
C. protected
D. unspecified
ANSWER: C

Q9. Which of the following is wrong about Inheritance?


A. It is one of the concepts of Java’s Object-Oriented Programming.
B. A subclass inherits the instance variables and methods of the superclass.
C. The methods in subclass which has the same names as superclass does not override the one
in superclass.
D. Constructors in superclass are not inherited by subclasses.
ANSWER: C

Q10. Which of the following is not a Java features?


A. Architecture Neutral
B. Distributed
C. Low-level programming
D. Portable
ANSWER: C

Level 2 Asia Pacific University of Technology & Innovation 2024


Downloaded by Prashant Acharya (prashantacharya436@[Link])
lOMoARcPSD|49629040

CT038-3-2-OODJ Final Exam Page 7 of 10

Q11. Which of the following for variable declaration is not valid?


A. byte a = 127;
B. string b = “Alex”;
C. double c = 3.201;
D. float d = 7.23f;
ANSWER: B

Q12. What is the result of the following program?

A. A
B. B
C. C
D. None, because there is at least one compile-time error.
ANSWER: B

Level 2 Asia Pacific University of Technology & Innovation 2024


Downloaded by Prashant Acharya (prashantacharya436@[Link])
lOMoARcPSD|49629040

CT038-3-2-OODJ Final Exam Page 8 of 10

Q13. What is the result of the following program?

A. 10 times *
B. 9 times *
C. 1 time *
D. None, because there is at least one compile-time error.
ANSWER: C

Q14. Which of the following condition is correct will display the correct message based on the i value?

A. i%2 >= 0
B. i%2 > 0
C. i%2 <= 0
D. i%2 < 0
ANSWER: B

Q15. Which of the following for array declaration is valid?

A. I, II, and IV only


B. II and IV only
C. I and III only
D. All of the mentioned
ANSWER: D

Q16. What is the result and its datatype when the user key in 4 into the system?

Level 2 Asia Pacific University of Technology & Innovation 2024


Downloaded by Prashant Acharya (prashantacharya436@[Link])
lOMoARcPSD|49629040

CT038-3-2-OODJ Final Exam Page 9 of 10

A. 10 and “int”
B. 4 and “int”
C. 4 and “double”
D. 4 and “char”
ANSWER: A

Q17. Which if statement below is equivalent to the given switch statement (that is, produce the same
output under the same conditions)? Assume _num_ is a previously declared int.

A. i and iv only
B. ii and iv only
C. ii and iii only
D. All of the above
ANSWER: A

Q18. CAN WE HAVE MULTIPLE CLASSES IN SAME JAVA FILE?


A. True
B. False
ANSWER: A

Level 2 Asia Pacific University of Technology & Innovation 2024


Downloaded by Prashant Acharya (prashantacharya436@[Link])
lOMoARcPSD|49629040

CT038-3-2-OODJ Final Exam Page 10 of 10

Q19. Given the values for i and j as below, which of the following while loop statement will not compile?
int i = 5;int j = 10;
A. while(i <= j) {}
B. while(i) {}
C. while((i = 12)==5) {}
D. while((i = 12)!=5) {}
ANSWER: B

Q20. Given:

abstract class Writer {


public static void write() {
[Link]("Writing...");
}
}
class Author extends Writer {
public static void write() {
[Link]("Writing book");
}
}
public class Programmer extends Writer {
public static void write() {
[Link]("Writing code");
}
public static void main(String[] args) {
Writer w = new Programmer();
[Link]();
}
}

What is the result?


A. Writing...
B. Writing book
C. Writing code
D. Compilation fails.
ANSWER: A

Level 2 Asia Pacific University of Technology & Innovation 2024


Downloaded by Prashant Acharya (prashantacharya436@[Link])

You might also like