Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

DAMBI DOLLO UNIVERSITY

COLLEGE OF ENGINEERING AND TECHNOLOGY


Department of Computer Science
Object-oriented Programming
Final Exam (50%)

Time allowed: 2:30 hr.

Name: ____________________
ID No: ____________________
Rules:
 Make sure you switch off your mobile!
 Any cheating is Not allowed!

Part 1 (15%) Part 2(20%) Part 3 (15%) Total (50%)

Exam committee
No name sign
1 _______________ ________________
2 _______________ ________________
3 _______________ ________________
Part 1: Read the following question and write true for correct statement and write false for incorrect
statement (1 for each).

1. There can be a try block without catch block but vice versa is not possible.
2. Inheritance Creates has-a relationship.
3. Protected is a visibility modifier that helps in inheritance situations.
4. Assigning a child object to a parent reference is considered to be a narrowing conversion, and can be
performed by simple assignment.
5. An interface name can be used as the type of an object reference variable.
6. Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword
extends.
7. An Abstract class can be instantiated.
8. The methods that implement an interface must be declared public.
9. While running your code if a stack overflow occurs, an error will arise.
10. The built-in packages are the packages created by the user.

Part 2: Read the following question and choose the correct answer accordingly (1.5 for
each).

1) While importing, if we use asterisk an import statement tells the compiler:

a) The path of a class b) the entire package c) particular class d) none

2) Which of the is not Abstract Classes Properties

a) A class declared abstract, even with no abstract methods cannot be instantiated.

b) A subclass of an abstract class can be instantiated if it overrides all abstract methods by implementing
them.

c) A class with one or more abstract methods is automatically abstract and it cannot be instantiated.

d) A subclass that does not implement all of the superclass abstract methods is itself abstract; and it can be
instantiated.
3) In Java, we can access static member of a class directly by using:

a) Import statement b) fully-qualified name c) static import statement d) asterisk

4) Which of these classes are the direct subclasses of the Throwable class?

a. RuntimeException and Error class b. Exception and VirtualMachineError class

c. Error and Exception class d. IOException and VirtualMachineError class

5) Which keyword is used for accessing the features of a package?

a) Package b) import c) extends d) export

6) What is an exception?

a) Problem arising during compile time b) Problem arising during runtime

c) Problem in syntax d) Problem in IDE

7) If a file that needs to be opened is not found in the target location then _____________

a) Exception will be produced b) Exceptions are not produced

c) Exception might get produced because of syntax d) Exceptions aren’t produced b/c of logic

8) Why do we use finally block?

a) To execute the block if exception occurred b) To execute a code when exception is not occurred

c) To execute a code whenever required d) to execute a code with each and every run of program

9) Which among the following best defines single level inheritance?

a) A class inheriting a derived class b) A class inheriting a base class

c) A class inheriting a nested class d) A class which gets inherited by 2 classes

10) An exception may arise when _______________

a) Input is fixed b) Input is some constant value of program

c) Input given is invalid d) Input is valid


11) ___________ is the mechanism by which a call to an overridden function is resolved at run time, rather
than compile time.

a) Dynamic method dispatch b) inheritance c) encapsulation d) abstraction

12) How many catch blocks can a single try block can have?

a) Only 1 b) Only 2 c) Maximum 127 d) as many as required

13) _______is a variable that can refer to different types of objects at different points in time.

a) Polymorphic reference b) type casting c) object reference d) call by reference

14) Which of the following keyword can prevent inheritance?

a) Abstract b) final c) super d) this

15) Which access type data gets derived as private member in derived class?

a) Private b) Public c) Protected d) Protected and Private

16) Members which are not intended to be inherited are declared as ________________

a) Public members b) Protected members c) Private members d) default

17) _____ can be defined as a grouping of related types (classes, interfaces, enumerations and annotations)
providing access protection and namespace management.

a) Class b) package c) exception d) object

18) Which one is odd?

a) ArithmeticException b) ClassNotFoundException

c) NullPointerException d) IllegalArgumentException

19) Which statement is wrong about overriding and overloading methods?

a) Overriding deals with two methods, one in a parent class and one in a child class, that have the same
signature

b) Overloading deals with multiple methods with the same name in the same class, with the same
signatures
c) Overloading lets you define a similar operation in different ways for different data

d) Overriding lets you define a similar operation in different ways for different object types

20) Which of the following statement is not correct?

a) A catch clause cannot exist without a try statement.

b) It is compulsory to have finally clauses whenever a try/catch block is present.

c) The try block cannot be present without either catch clause or finally clause.

d) All are correct.

Part 3: Answer the following question accordingly

1) Distinguish between checked and unchecked exceptions. Support your answer with examples. (4%)
2) Discuss at least three ways to import classes and interfaces of another package. (3%)
3) Distinguish between dynamic and late binding. (2%)
4) What are system errors? Explain briefly by giving examples. (3%)
5) What will the output of the following java programming be? (3%)

public class Animal {


private String name;
public Animal(String n) { name = n;}
public String getName() { return name; }
}
public class Dog extends Animal {
private int fleas;
public Dog(String n, int f) {
super(n); // calls Animal constructor
fleas = f;
}
public int getFleas() {return fleas; }
public void speak() { return System.out.println("Woof"); }
}
public class Cat extends Animal {
private int hairballs;
public Cat(String n, int h) {
super(n); // calls Animal constructor
hairballs = h;
}
public int getHairballs() { return hairballs; }
public void speak() { return System.out.println("Meow"); }
}
Public static void main ( String []args){
Dog d = new Dog("Rover“, 3);
Cat c = new Cat("Kitty", 2);
System.out.println(d.getName() + " has " +
d.getFleas() + " fleas");
System.out.println(c.getName() + " has " +
c.getHairballs() + " hairballs");
}

You might also like