Department of Computer Science: COMSATS University Islamabad, Abbottabad Campus

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

COMSATS University Islamabad, Abbottabad Campus

Department of Computer Science

SESSIONAL –II EXAMINATION – FALL 2020


Class: BSE 3B Date: 1st DEC 2020
Subject: Object Oriented Programming Max Marks: 45
Time Allowed: 90 min.

1. In the following options infect which is not the type of inheritance?


a. Single inheritance b. Double inheritance
c. Hierarchical inheritance d. Multiple inheritance

2. Determine the output of the following inheritance code segment?


class A{
public int i;
public int j;
A(){
i = 1;
j = 2;
}
}//A
class B extends A{
int a;
B() {
super();
}
}
//main . . .
B ob = new B();
System.out.println(ob.i+ " " +ob.j);

a. 1 2 b. No output
c. Run time error d. Compile time error

3. All classes in Java are inherited from which class? Pick a suitable option.
a. java.lang.class b. java.class.inherited
c. java.class.object d. java.lang.Object

4. Which of the following is used for implementing inheritance through an interface?


a. inherited b. using super
c. extends d. implements

5. Determine which of the following option suits to you if a class extends two interfaces and
both have a method with same name and signature?
a. Runtime error b. Compile time error
c. Code runs successfully
d. First called method is executed successfully

6. Which of the following options can be used to avoid Method overriding?


a. private b. constant
c. protected d. final

7. Which of the following options match the garbage collection in Java?


a. When all references to an object are gone, the memory used by the object is
automatically reclaimed
b. The operating system periodically deletes all of the java files available on the system.
c. Any package imported in a program and not used is automatically deleted.
d. JVM checks output of any Java program and deletes anything that doesn't make sense.

8. Which of these is correct way of calling a constructor having no parameters, of superclass


A by subclass B?
a. super; b. superA();
c. super.A(); d. super();

9. At line number 2 below, choose 3 valid data-type attributes/qualifiers among “final,


static, native, public, private, abstract, protected”
public interface Test{ //line 1
/* insert qualifier here */ int x = 99; //line 2
}
a. final, native, private
b. final, static, protected
c. final, private, abstract
d. public, static, final
10. Which of the following choices being supported by method overriding in OOP?
a. Abstraction b. interface
c. Polymorphism d. overloading

11. Which of the following is true statement(s)?

1. A class can extend only one class but many interfaces.


2. An interface can extend many interfaces.
3. An interface can implement many interfaces.
4. A class can extend one class and implement many interfaces.

a. 1 and 2 b. 2 and 3
c. 2 and 4 d. 3 and 4

12. The concept of multiple inheritance is implemented in Java by


I. Extending two or more classes.
II. Extending one class and implementing one or more interfaces.
III. Implementing two or more interfaces.
a. Only (II) b. (I) and (II)
c. (II) and (III) d. Only (I)

13. A class member declared protected becomes member of subclass of which type?
a public member b. private member
c. protected member d. static member

15. In your opinion which one of the following statements is legal?


a. "B extends A" is correct if and only if B is a class and A is an interface
b. "B extends A" is correct if and only if B is an interface and A is a class
c. "B extends A" is correct if B and A are either both classes or both interfaces
d. "B extends A" is correct for all combinations of B and A being classes or interfaces

16. What is the output of the following program?


final class A {
int i;
}
class B extends A{
int j;
System.out.println(j + " " + i);
}
class Test{
public static void main(String args[]){
B ob = new B();
ob.display();
} }
a. 0 0 b. Garbage
c. Runtime Error d. Compilation Error

17. What is the output of this program?


class A{
public static void main(String[] args){
String[] str = { "Muhammad", "Umar", "Khan" };
String test = (str.length > 0) ? str[0]:str[1];
} }
a. The variable test is set to str[1]
b. An exception is thrown at run time
c. The variable test is set to null
d. The variable test is set to str[0]

18. What is the output of this program segment?


class A {
public int i;
protected int j;
}
class B extends A {
int j;
void display() {
super.j = 3;
System.out.println(i + " " + j);
} }
//main. . .
B ob = new B();
ob.i=1; ob.j=2;
ob.display();
a. 1 2 b. 2 1
c. 1 3 d. 3 1

19. What is the output of the following code segment?


class A{
final void test(){
System.out.println(“I am in A class.”);
}
}//A
class B extends A{
void test(){
System.out.println(“I am in B sub-class.”);
}
}//B
//main. . .
B ob = new B();
ob.test();
a. I am in B sub-class b. I am in A class
c. Both a & b d. Compile time error

20. Which of the following is a true statement about a subclass concept?


a. A subclass is a class that extends another class
b. A subclass is a class declared inside a class
c. Both a & b
d. None of the above

21. In Inheritance the order of execution of constructors is _________________


a. Base to derived class b. Derived to base class
c. Random order d. None
22. Suggest which one is a type of polymorphism in your opinion?
a. Compile time polymorphism b. Execution time polymorphism
c. Multiple polymorphism d. Multilevel polymorphism

23. Which theory is suitable of converting real world objects in terms of class?
a. Polymorphism b. Encapsulation
c. Abstraction d. Inheritance

24. A class can be declared as _________ if you do not want the class to be subclass. Using
the __________keyword we can abstract a class interface from its implementation.
a. protected, interface b. final, interface
c. public, friend d. final, protected

25. Which of the following is correct way of implementing an interface salary by class
manager?
a. class manager implements salary { }
b. class manager extends salary { }
c. class manager imports salary { }
d. None of the mentioned

27. Which one of the following theory of polymorphism being applied to inheritance
relationship in OOP using Java?
a. Method overloading b. Constructor overloading
c. Method overriding d. None

28. Determine which statement is true concept about a static nested class?
a. You must have a reference to an instance of enclosing class in order to instantiate it.
b. It does not have access to non-static members of the enclosing class.
c. It's variables and methods must be static.
d. It must extend the enclosing class.
30. Which of these can be used to fully abstract a class from its implementation?
a. Objects b. Packages
c. Interfaces d. None of above

31. What does an interface contain___________________?


a. Method definition b. Method declaration
c. Method declaration and definition d. Method name

32. Which one of the following class definition defines a legal abstract class?
a. class A { abstract void unfinished() { } }
b. class A { abstract void unfinished(); }
c. abstract class A { abstract void unfinished(); }
d. public class abstract A { abstract void unfinished(); }

33. Which of the following is correct interface?


a. interface A {void print() { } }
b. abstract interface A { print(); }
c. abstract interface A { abstract void print(); { }}
d. interface A {void print(); }
34. Final keyword in java is used with which of the following options?
a. class b. class attributes
c. class methods d. All of above

35. False statement about final method in java is___________


a. Value of final variable cannot be changed once initialized.
b. Final method is inherited but we cannot override it
c. If you make a class final then you cannot extend the class
d. Constructor can be declared as final.

Question 2 (10)
You are directed to design a Java program for creating and manipulating entries in a telephone book.
Consider the following class definition for a Person entry in a telephone book.
class Person{
String name;
int number;
Person(String s, int n){
number = n;
name = s;
}
}

a) The telephone book is an array of 1000 Person entries and also an integer that records the number
of entries in the telephone book. Implement a method display() that displays the details of every
person in the telephone book.

b) Give the implementation of a method add_person() that reads a last name and a telephone number
from the user, creates a new person, and adds the person to the end of the array if there is space.
.
c) Give the implementation of a method find_person() that takes a telephone number and displays the
person name with the corresponding telephone number. You may assume that the given telephone
number exists in the telephone book and that the telephone book contains at least one person.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy