To Prepare Model Exam OOP Question

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

Bahir Dar University

Bahir Dar institute of Technology


Computing Faculty
Object Oriented Programming Question

1. Which translator the individual steps in a high-level program one at a time rather than the
whole program as a single unit.
a) Interpreter
b) Assembler
c) Compiler
d) JVM
e) All
2. It is based on commands that update variables in storage and control flow is an explicit
sequence of commands.
a) Imperative or procedural
b) Declarative
c) Logical or rule based
d) Functional
e) None
3. What is procedure-oriented Language?
a) A procedure-oriented Language is a language that incorporates all object-oriented
programming features
b) A procedure-oriented Language is a language that supports encapsulation and object
identity
c) A procedure-oriented Language is a language that consists of writing a list of
instructions
d) A procedure-oriented Language is a language that does not support Inheritance and
Dynamic binding
4. Which one is false about java Key features?
a) Platform-independent
b) Simple
c) Centralize
d) Portable
e) Multithreaded
5. Which one is not java identifiers
a) intab
b) _ab
c) All are possible
d) a-bc
e) a$b
6. Which one is true about Java platform
a) JRE is a superset of the JDK
b) JRE = JVM + Java Packages of Classes+ runtime libraries
c) JDK is a superset of the JRE
d) All are correct
7. Which converted type is Casting with a larger range to a type with a small range
a) Narrowing a type
b) Widening a type
c) Explicit casting
To prepare model exam
1
d) Implicit casting
8. Which one is false about while and do while loop
a) Bothe are the same syntax
b) While loop syntax first execute then check the expression
c) Do While loop syntax first check the expression then execute
d) All are false
e) All are true
9. int x=3;

y = (x > 0) ? 5 : 6; what is the value of y?

a) 5
b) 0
c) 6
d) None

10. Which is not a feature of OOP in general definitions?


a) Efficient Code
b) Code reusability
c) Modularity
d) Duplicate/Redundant data

11. Which was the first purely object oriented programming language developed?
a) Kotlin
b) SmallTalk
c) Java
d) C++
12. Which feature of OOP indicates code reusability?
a) Abstraction
b) Polymorphism
c) Encapsulation
d) Inheritance
13. Which among the following doesn’t come under OOP concept?
a) Data hiding
b) Message passing
c) Platform independent
d) Data binding
14. Which is the correct syntax of inheritance?
a) class base_classname extends derived_classname{ /*define class body*/ };
b) class derived_classname extends base_classname{ /*define class body*/ };
c) class derived_classname base_classname{ /*define class body*/ };
d) class base_classname derived_classname{ /*define class body*/ };

15. Which feature of OOP is indicated by the following code?

To prepare model exam


2
class student{ int marks; };
class topper:public student{ int age; topper(int age){ this.age=age; } };

a) Encapsulation and Inheritance


b) Inheritance and polymorphism
c) Polymorphism
d) Inheritance

15. What is encapsulation in OOP?


a) It is a way of combining various data members and member functions that operate on those
data members into a single unit
b) It is a way of combining various data members and member functions into a single unit which
can operate on any data
c) It is a way of combining various data members into a single unit
d) It is a way of combining various member functions into a single unit

16. Which of the following is not true about polymorphism?


a) Helps in redefining the same functionality
b) Increases overhead of function definition always
c) It is feature of OOP
d) Ease in readability of program

Based on the following code answer question number from 17 and 19


double x = 2.0;
double y = 8.0;
double z = x-- + (++y);
x--;
System.out.println(" X= " +x);
System.out.println(" Y= " +y);
System.out.println(" Z= " +z);

17. Which one is true about the output of the X


a) X= 0.0
b) X=2.0
c) X= 1.0
d) None

18. Which one is true about the output of the Y


a) Y = 11.0
b) Y =9.0
c) Y = 10.0
d) Y= 8.0
e) None

19. Which one is true about the output of the Z


a) Z= 10.0
To prepare model exam
3
b) Z=9.0
c) Z= 11.0
d) Z=12.0
e) None

20. Which one is true about to Creating Two-Dimensional Arrays(3 row and 4 column) the
array reference variable is List and the element type is Double
a) double list[][]= double[3][4];
b) double[][] list= new double[3][4];
c) double [][] list= new double[4][3];
d) double list[][]= new[4][3]double;

21. Which one is true to assign the value 5.5 on the * place the array reference variable is List

a) list[3][2]=5.5;
* b) list[2][3]=5.5;
c) list[1][2]=5.5;
d) list[2][1]=5.5;
22. Which of the following statements is false?
a) A public class can be accessed by a class from a different package.
b) A private method cannot be accessed by a class in a different package.
c) A protected method can be accessed by a subclass in a different package.
d) A method with default modifier can be accessed by a class in a different package
23. What is the output of the following code?

public class Employee{


private String name;
private int age;
private double salary;
private boolean attendance;
public static void main(String[] args){
Employee emp = new Employee();
System.out.print(emp.name+" "+emp.age+" "+emp.attandance+" "+emp.salary);
}
}

a) null 0.0 false 0


b) 0 false 0.0 null
c) null 0 false 0.0
d) null 0.0 false 0

24. Which of the following modifier is not accessible in another class in different package
but is accessible to any subclasses in any package?
a) public

To prepare model exam


4
b) private
c) protected
d) Use the default modifier.
25. Which of the following is correct about static and instance?
a) An Instance method can invoke static method
b) A static method can invoke instance method
c) A static method can access instance data fields directly without object
d) A static method is inherited the subclass
26. Inheritance means that ______________.
a) data fields should be declared private.
b) a class can extend another class.
c) a variable of super type can refer to a subtype object.
d) a class can contain another class.
27. Which constructor will be called from the object created in the below C++ code?

class A
{
int i;
A()
{
i=0; cout<<i;
}
A(int x=0)
{
i=x; cout<<I;
}
};
A obj1;

a) Parameterized constructor
b) Default constructor
c) Run time error
d) Compile time error
28. What is an abstraction in object-oriented programming?
a) Hiding the implementation and showing only the features
b) Hiding the important data
c) Hiding the implementation
d) Showing the important data
29. In which access should a constructor be defined, so that object of the class can be created in
any function?
a) Any access specifier will work
b) Private
c) Public
d) Protected

30. Which among the following is correct for the class defined below?

class student
{
int marks;

5
public: student(){}
student(int x)
{
marks=x;
}
};
main()
{
student s1(100);
student s2();
student s3=100;
return 0; }

a) Program will give compile time error


b) Object s3, syntax error
c) Only object s1 and s2 will be created
d) Program runs and all objects are created
31. The copy constructors can be used to ________
a) Copy an object so that it can be passed to another primitive type variable
b) Copy an object for type casting
c) Copy an object so that it can be passed to a function
d) Copy an object so that it can be passed to a class
32. Which constructor will be called from the object obj2 in the following C++ program?

class A
{
int i;
A()
{
i=0;
}
A(int x)
{
i=x+1;
}
A(int y, int x)
{
i=x+y;
}
};
A obj1(10);
A obj2(10,20);
A obj3;

a) A(int y, int x)
b) A(int y; int x)
c) A(int y)
d) A(int x)

33. Which among the following represents correct constructor?


a) –classname()
b) classname()
c) ()classname
d) ~classname()
6
34. What happens when an object is passed by reference?
a) Destructor is called at end of function
b) Destructor is called when called explicitly
c) Destructor is not called
d) Destructor is called when function is out of scope

Based the following code answer question numbers from 36 to 41

public class ComputingFaculity{


private String location;
public ComputingFaculity(){
System.out.println("class of Computing Faculty");
}
public String getLocation(){
return location;
}
public void setLocation(String loc){
location = loc;
}
}
class ComputerScience extends ComputingFaculity{
public ComputerScience(){
System.out.println("class of Computer Science");
}
}
class IT extends ComputingFaculity{
public IT(){
System.out.println("class of IT");
}
public void display(){
System.out.println("this is display method IT class");
}
}
class Section extends IT{
static int num_Section = 0;
public Section(){
System.out.println("class of Section ");
}
public void display(){
System.out.println("this is display method in section class");
}
}
class Test{
public static void main (String[] args) {
new SectionF();
}
}

36. What is the file name of the above program?


a) Circle.java
b) ComputingFaculity.java

7
c) Computer Science.java
d) SectionF.java
e) None

37. What is the relationship between ComputingFaculity and Section classes?


a) Composition relationship
b) Inheritance relationship
c) is-a relationship
d) A and C
e) B and C

38. Which one is false statement?

a) ComputingFaculity obj = new ComputingFaculity();


b) IT obj = new IT();
c) IT obj = new Section();
d) IT obj = new ComputingFaculity ();
e) None
39. Which one is overridden method?
a) display()
b) getLocation()
c) setLocation()
d) IT()
e) None
40. What is the output of the above program?
A. class of Computing Faculty
class of IT
class of Section

B. class of Section
class of Computing Faculty
class of IT

C. class of Section
class of IT
class of Computing Faculty

D. None
41. Which one of the following is false statement about the object created by Section obj =
new Section();
a) obj instanceof ComputingFaculity
b) obj instanceof IT
c) obj instanceof Section
d) obj instanceof ComputerScience
e) None

8
42 How to access data members of a class?
a) Dot, arrow or direct call
b) Dot operator
c) Arrow operator
d) Dot or arrow as required

43. Which keyword among the following can be used to create an array of objects in java?
a) allocate
b) arr
c) new
d) create
44. Which of the following is not a property of an object?
a) Properties
b) Names
c) Identity
d) Attributes

45. Which type of members can’t be accessed in derived classes of a base class?
a) All can be accessed
b) Protected
c) Private
d) Public
46. Which among the following best describes the Inheritance?
a) Using the data and functions into derived segment
b) Using already defined functions in a programming language
c) Using the code already written once
d) Copying the code already written
47. What happens if non static members are used in static member function?
a) Executes fine
b) Compile time error
c) Executes if that member function is not used
d) Runtime error
48. Where is the memory allocated for the objects?
a) Cache
b) ROM
c) HDD
d) RAM

49. Which of the following best describes member function overriding?


a) Member functions having the same name in derived class only
b) Member functions having the same name and different signature inside main function
c) Member functions having the same name in base and derived classes
d) Member functions having the same name in base class only

50. Encapsulation and abstraction differ as ____________


a) Hiding and hiding respectively
b) Binding and Hiding respectively

9
c) Hiding and Binding respectively
d) Can be used any way
51. Which feature of OOP is exhibited by the function overriding?
a) Polymorphism
b) Encapsulation
c) Abstraction
d) Inheritance
52. How to access the private member function of a class?
a) Using class address
b) Using object of class
c) Using object pointer
d) Using address of member function
53. Which keyword should be used to declare static variables?
a) const
b) common
c) static
d) stat
54. Which is correct syntax for declaring pointer to object?
a) *className objectName;
b) className* objectName;
c) className objectName();
d) className objectName;
55. Which class/set of classes can illustrate polymorphism in the following C++ code?

abstract class student


{
public : int marks;
calc_grade();
}
class topper:public student
{
public : calc_grade()
{
return 10; } };
class average:public student
{
public : calc_grade()
{
return 20;
}
};
class failed{ int marks; };
a) Only class student and topper together can show polymorphism
b) Only class student can show polymorphism
c) Class failed should also inherit class student for this code to work for polymorphism
d) All class student, topper and average together can show polymorphism
56. If data members are private, what can we do to access them from the class object?
a) Private data members can never be accessed from outside the class
b) Create public member functions to access those data members

10
c) Create private member functions to access those data members
d) Create protected member functions to access those data members
57. Which among the following is not a necessary condition for constructors?
a) Its name must be same as that of class
b) It must not have any return type
c) It must contain a definition body
d) It can contains arguments
58. Object being passed to a copy constructor ___________
a) Must not be mentioned in parameter list
b) Must be passed with integer type
c) Must be passed by value
d) Must be passed by reference
59. If in multiple inheritance, class C inherits class B, and Class B inherits class A. In which
sequence are their destructors called if an object of class C was declared?
a) ~A() then ~B() then ~C()
b) ~C() then ~A() then ~B()
c) ~C() then ~B() then ~A()
d) ~B() then ~C() then ~A()
60. Instance of which type of class can’t be created?
a) Parent class
b) Abstract class
c) Anonymous class
d) Nested class
61. ___________ underlines the feature of Polymorphism in a class.
a) Virtual Function
b) Inline function
c) Enclosing class
d) Nested class
62. Which feature in OOP is used to allocate additional functions to a predefined operator in any
language?
a) Function Overloading
b) Function Overriding
c) Operator Overloading
d) Operator Overriding
63. Which feature can be implemented using encapsulation?
a) Polymorphism
b) Overloading
c) Inheritance
d) Abstraction

11
Based the following code answer question numbers from 64 to 70
1. package bookInfo;
2. public class Book {
3. private String title;
4. private String authName;
5. protected float price;
6. private static int num = 0;
7. public Book(String t, String n, float p){
8. title = t;
9. authName = n;
10. price = p;
11. num++;
12. }
13. public String getTitle(){
14. return title;
15. }
16. public void setTitle(String title){
17. this.title = title;
18. }
19. public String getAuthName(){
20. return authName;
21. }
22. public void setAuthName(String name){
23. this.authName = name;
24. }
25. public float getPrice(){
26. return price;
27. }
28. public void setPrice(float price){
29.
30. }
31. public static int getNum(){
32. return num;
33. }
34. }
35. class TestBook{
36. public static void main (String[] args) {
37.
]
38. }
39. }

64. Which of the following statement is correct when you insert at line 29?
A. = price; C. this.price = price;
B. price = this.price; D. None
65. Which of the following is a local variable in the above program?
A. title C. name
B. authName D. All
66. Which line of code is a package name in the above program?
A. Line 2 D. Line 32
B. Line 1 E. None
C. Line 3

12
67. Which of the following statement is correct to access variable num inside the main() method
of TestBook class?
A. TestBook.num; D. testbook.num;
B. Book.num; E. None
C. book.num;
68. Which of the following statement is correct to access title inside the main() method of
TestBook class using the object created: Book bk = new Book("computer",
"William Jems", 56)?
a) System.out.println(bk.title);
b) System.out.println(title);
c) System.out.println(bk.getTitle());
d) System.out.println(getTitle());
69. Which one is correct statement to call/invoke method getNum () inside the main() method?
A. Book.getNum(); D. getNum();
B. TestBook.getNum(); E. None
C. book.getNum();
70. Which of the following statement is false?
a) Book bk = new Object();
b) Object obj = new Book();
c) Object obj = new Object();
d) None
71. Which one of the following statement is true
a) A has-a relationship is implements via inheritance.
b) A House class has is-a relationship with door
c) On java it is possible subclass redefied a superclass method.
d) Superclass constructer is not inherited by sub class
e) all are correct
72. Inheritance means that __________
a) Data filed should be declared private.
b) A class can extends anther class
c) A variable of super type can refer to a subtype object
d) A class can contain anther class.
e) all are answer
73. Which of the following is false
a) “Class A extends B” means B is subset of A
b) A subclass is a subset of superclass
c) Subclass contain specific data filed and functionality in addition to the superclass
member.
d) Super class is define common behavior for related and unrelated classes.

13
e) Nane
74. Which error occur when a program doesn't perform the way it was intended to.
a) Logic errors
b) Syntax errors
c) Runtime errors
d) Runtime and Logic errors
e) None

75. Which two features of object-oriented programming are the same?


a) Abstraction and Polymorphism features are the same
b) Inheritance and Encapsulation features are the same
c) Encapsulation and Polymorphism features are the same
d) Encapsulation and Abstraction
76. Which among the following cannot be used for the concept of polymorphism?
a) Static member function
b) Constructor Overloading
c) Member function overloading
d) Global member function
77. Which function best describe the concept of polymorphism in programming languages?
a) Class member function
b) Virtual function
c) Inline function
d) Undefined function
78. Which of the following feature is also known as run-time binding or late binding?
a) Dynamic typing
b) Dynamic loading
c) Dynamic binding
d) Data hiding
79. Which of the following OOP concept binds the code and data together and keeps them
secure from the outside world?
a) Polymorphism

14
b) Inheritance
c) Abstraction
d) Encapsulation

80. Which of the following variable violates the definition of encapsulation?


a) Array variables
b) Local variables
c) Global variables
d) protected variables
81. The concept of encapsulation helps in writing which type of classes in the Java
programming language?
a) Abstract classes
b) Wrapper classes
c) Mutable classes
d) Immutable classes
82. Which of the following syntax is incorrect for the class definition?
a) student class{ };
b) class student{ student(int a){} };
c) class teacher{ public: teacher(int a){ } };
d) None of the mentioned
83. The object cannot be________?
a) passed by copy
b) passed as function
c) passed by value
d) passed by reference
84. Which of the following definition best describes the concept of polymorphism?
a) It is the ability to process the many messages and data in one way
b) It is the ability to process the undefined messages or data in at least one way
c) It is the ability to process the message or data in more than one form
d) It is the ability to process the message or data in only one form

15
85. ____ is considered to be a partitioned area of computer memory that stores and set of
operations that can access the data.

a) Classes
b) Objects
c) Variables
d) Functions

86. Objects are the variables of the type ____?


a) String
b) Boolean
c) Class
d) All data types can be included

87. Why classes are known as abstract data types (ADT)?


a) Because classes are user-defined data types
b) Because it supports the theory of hierarchical classification
c) Because it allows dynamic binding
d) Because it uses the concept of data abstraction

88. Which is not true about the object-oriented approach?


a) Emphasis is on data rather than procedure
b) Data is hidden and cannot be accessed by external functions
c) Objects communicate through functions
d) It supports abstract data but not the class

89. ____ is the process of compartmentalizing the elements of an abstraction that contribute
to its structure and behavior?
a) Encapsulation
b) Abstraction
c) Classes
d) Inheritance

90. A _____ object gets its memory allocated at runtime.

a) Static objects
b) Dynamic objects
c) a and b

91. A _____ object gets its memory allocated at compile time.

16
a) Static objects
b) Dynamic objects
c) a and b
92. Which access specifier makes the class member accessible outside the class but can be
accessed by any subclass of that class?

a) Private
b) Public
c) Protected

93. Which access specifiers have strict access control?

a) Private
b) Public
c) Protected

94. When an object is created an initialization needs to be done which is automatically done
by the ____ function?

a) Constructor
b) Destructor
c) Friend
d) Member

95. _____ is associated with polymorphism and inheritance.

a) Message parsing
b) Abstraction
c) Dynamic Binding
d) Encapsulation

96. The scope resolution operator is used to ____ function in the Inheritance.

a) Overload
b) Override

97. Which one is false about implicit and explicit casting object?

a) Object o = new Student(); Implicit casting

17
b) Student b = o; Implicit casting
c) Student b = (Student)o; Explicit casting
d) All are true

98. Which one is false about abstract classes and interfaces?

a) All Interfaces variables must be public static final


b) All Interfaces methods must be public abstract instance methods
c) Both abstract class and interface cannot be instantiated using the new operator
d) Abstract class constructors are invoked by subclasses through constructor chaining.
e) All are true

99. Which one is true to create using inner non-static class object

a) OuterClass.InnerClass innerObject = outerObject. new InnerClass();


b) OuterClass.InnerClass innerObject = new OuterClass.InnerClass();
c) InnerClass .OuterClass innerObject = new outerObject. InnerClass();
d) OuterClass.InnerClass innerObject = new InnerClass OuterClass ();

100. Which one is false about finally block is executed on exceptions?


a. If no exception arises in the try block, final Statements is executed, and the next
statement after the try statement is executed.
b. If a statement causes an exception in the try block that is caught in a catch block, the
rest of the statements in the try block are skipped, the catch block is executed, and the
finally clause is executed. The next statement after the try statement is executed.
c. If one of the statements causes an exception that is not caught in any catch block, the
other statements in the try block are skipped, the finally clause is executed, and the
exception is passed to the caller of this method
d. All are correct

18

You might also like