Department of Computer Science: COMSATS University Islamabad, Abbottabad Campus
Department of Computer Science: COMSATS University Islamabad, Abbottabad Campus
Department of Computer Science: COMSATS University Islamabad, Abbottabad Campus
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
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
a. 1 and 2 b. 2 and 3
c. 2 and 4 d. 3 and 4
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
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
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(); }
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.