Mcq Of Object Oriented Programming - I-3140705 PDF

Title Mcq Of Object Oriented Programming - I-3140705
Course Object Oriented Programming - I
Institution Gujarat Technological University
Pages 34
File Size 439.3 KB
File Type PDF
Total Downloads 78
Total Views 150

Summary

It is a Multiple Choice Questions Bank with answers....


Description

Multiple Choice Questions Bank

OOP 1 3140705

Unit – 1 to 6 1. Which of the following is true? a. Java uses only interpreter b. Java uses only compiler. c. Java uses both interpreter and compiler. d. None of the above. Ans: (c) 2. A Java file with extension ‘.class’ contains a. Java source code b. HTML tags c. Java Byte code d. A program file written in Java programming language Ans: (c) 3. Applet execution is a. Server sided b. Client sided c. Both a and b d. None of the above Ans: (b) 4. Which of the following is a Class in Java? a. int b. String c. short d. double Ans: (b)

1

Multiple Choice Questions Bank

OOP 1 3140705

5. Which of the following is not a correct statement? a. It is always necessary to use new operator to initialize an array. b. Array can be initialized using comma separated expressions surrounded by curly braces. c. Array can be declared and memory can be allotted in one statement. d. An array can be declared in one statement and memory can be allocated in other statement. Ans: (a) 6. Which of the following is an incorrect array declaration? a. int[] a = new int[10]; b. int [ ] a; c. int[][] a = new int[10]; d. int[][] a = {{1, 2, 3}, {1, 2, 3}}; Ans: (c) 7. Which of the following cannot be used for a variable name in Java? a. identifier b. final c. malloc d. calloc Ans:(b) 8. Which of the following is not an object-oriented programming paradigm? a. Encapsulation b. Inheritance c. Polymorphism d. Dynamic memory allocation Ans:(d)

2

Multiple Choice Questions Bank

OOP 1 3140705

9. Which of the following features are not common in both Java and C++? a. The class declaration. b. The access modifiers. c. The encapsulation of data and methods. d. Multiple inheritance from class Ans:(d) 10. Java is a platform independent programming language because a. It is written almost similar to English language. b. It compiles to an intermediate code targeting a virtual machine, which can be interpreted by an interpreter for a given OS. c. Java compiler translates the source code directly to the machine level language. d. It follows the concept of “write once and compile everywhere”. Ans: (b) 11. So far the declaration of main() method is concerned, which of the following specification is not valid a. void b. public c. static d. private Ans: (d) 12. Which of the following is a valid specifier with the main() method? a. public b. private c. protected d. default (i.e., nothing)

3

Multiple Choice Questions Bank

OOP 1 3140705

Ans: (a) 13. Consider the following object declaration statement Scanner inp= new Scanner(System.in) What is System.inin this declaration? a. Any file storing data b. Reference to standard input device, that is, keyboard c. Reference to a scanner as an input device d. It is a mouse as an input device Ans: (b) 14. Which of the following is a valid declaration of an object of class, say Box? a. Box obj = new Box(); b. Box obj = new Box; c. obj = new Box(); d. new Box obj; Ans: (a) 15. Which of the following statement is incorrect? a. Every class must contain a main() method b. Applets do not require a main() method at all c. There can be only one main() method in a program d. main() method must be made public Ans: (a) 16. What is the output of the following program? public class Test { public static void main(String [ ] args) { Test t = new Test(); t.start(); }

4

Multiple Choice Questions Bank

OOP 1 3140705

void start(){ int a = 4; int b = 5; System.out.print("" + 8 + 3 + ""); System.out.print(a + b); System.out.print(" " + a + b + ""); System.out.print(foo() + a + b + " "); System.out.println(a + b + foo()); } String foo(){ return "foo"; } } a. 839 45foo45 9foo b. 9 7 7 foo34 34foo c. 72 34 34 foo34 34foo d. 9 7 7 foo 7 7foo Ans: (a) 17. What is the return type of a method that does not return any value? a. int b. float c. void d. double Ans: (c) 18. What is the process of defining more than one method in a class having the same name but differentiated by method signature? a. Method overriding b. Method overloading c. Encapsulation d. Inheritance Ans: (b)

5

Multiple Choice Questions Bank

OOP 1 3140705

19. Which of the following is called when a method having the same name as that the name of the class where it is defined? a. abstract b. this c. final d. constructor Ans: (d) 20. public class Test{ public static void main(String args[]){ int x = 9; if (x == 9) { int x = 8; System.out.println(x); } } } a. 8 b. 9 c. Compilation error. d. Runtime error. Ans: (c) 21. Which of the following statements is/ are incorrect? a. Two or more methods with the same name can be differentiated on the basis of their parameters data type. b. Two or more method having the same name can be differentiated on the basis of number of parameters. c. Any already defined method in Java library can be defined again in the program with different data type of parameters.

6

Multiple Choice Questions Bank

OOP 1 3140705

d. No method can call another method without creating an object of the class to which it is defined. Ans: (d) 22. What is the maximum number of arguments that can be passed to a method in Java? a. No arguments b. One c. Any number of arguments d. Varies from one compiler to another Ans: (c) 23. What is not the use of “this” keyword in Java? a. Passing itself to another method b. Calling another constructor in constructor chaining c. Referring to the instance variable when local variable has the same name d. Passing itself to method of the same class Ans: (d) 24. Which of the following is true about the break statement in Java? a. Break stops the execution of entire program. b. Break halts the execution and forces the control out of the loop. c. Break forces the control out of the loop and starts the execution of next iteration. d. Break halts the execution of the loop for certain time frame. Ans: (b) 25. Which of the following is usually used with the switch statement? a. continue b.

exit

c. break

7

Multiple Choice Questions Bank

OOP 1 3140705

d. do Ans: (c) 26. Which of these is used by operating system to manage the Recursion in Java? a. Array b.

Stack

c. Queue d. Tree Ans: (b) 27. Which of the following access specifier must be used for class so that a sub class can inherit it? a. public b.

private

c. protected d.

default

Ans: (a) 28. A class member declared as protected becomes member of subclass of which type? a. public member b.

private member

c. protected member d. default member Ans: (b) 29. Which inheritance in Java programming is not supported? a. Multiple inheritance using classes. b.

Multiple inheritance using interfaces.

c. Multilevel inheritance. d. Single inheritance.

8

Multiple Choice Questions Bank

OOP 1 3140705

Ans: (a) 30.

How can a protected member be accessed? a. Accessible only within the class. b.

Accessible only within package.

c. Accessible within the package as well as outside the package but through inheritance only. d. Accessible to everywhere. Ans: (c) 31. Order of execution of constructors in Java Inheritance is a. Base to derived class. b.

Derived to base class.

c. Random order. d. No execution of a constructor in the derived class. Ans: (a) 32. Which of this keyword can be used in a subclass to call the constructor of super class? a. super b. this c. extent d. extends Ans: (a) 33. Advantage(s) of inheritance in Java programming is/are a. Code sharing b.

Code maintainability

c. Code reusability d. All of the above Ans: (d)

9

Multiple Choice Questions Bank

OOP 1 3140705

34. If there is an abstract method in a class then, a. Class must be abstract class. b.

No object of the class can be created.

c. Any sub class of the class may or may be abstract class. d. All of the above. Ans: (d) 35. For each description on the left, find the best matching modifier on the right. You may use a choice more than once or not at all. 1. 2. 3. 4. 5.

Hides the instance variable from code in other files. Hides the method from code in other files. Hides the subclass from code in other files. Exposes the API method to code in other files. Prevents the value of the instance variable from being Changed once initialized. above

A. private B. public C. final D. static E. none of the

a. 1-A,2-A,3-C,4-D,5-E b. 1-A,2-A,3-A,4-B,5-C c. 1-C,2-B,3-A,4-A,5-D d. None of Above Ans: (b) 36. Suppose the class Undergraduate extends the class Student which extends the class Person. Given the following variable declaration: Person p = new Person(); Student s = new Student(); Undergraduate ug = new Undergraduate(); Which of the following assignments are legal? I. p = ug; II. p = new Undergraduate(); III. ug = new Student();

10

Multiple Choice Questions Bank

OOP 1 3140705

IV. ug = p; V. s = new Person(); a. I and IV b.

III, II and IV

c. I and II d. III and IV Ans: (c) 37. For which purpose packages are used in Java? a. Categorizes data b.

Organizing java classes into namespaces

c. For faster compilation d. None Ans: (b)

38. Which of the following keywords is used to define a package in Java? a. class b.

implements

c. extends d. package Ans: (d) 39. Which of the following is an incorrect statement about packages? a. Package defines a namespace in which classes are stored. b.

A package can contain other package within it.

c. Java uses file system directories to store packages. d. A package can be renamed without renaming the directory in which the classes are stored.

11

Multiple Choice Questions Bank

OOP 1 3140705

Ans: (d) 40. Which of these access-specifiers can be used for an interface? a. public b. private c. protected d. All of above Ans: (a) 41. Which of the following is an incorrect statement about Interfaces? a. Interfaces specify what class must do but not how it does. b.

Interfaces are specified public if they are to be accessed by any code in the program.

c. All variables in interface are implicitly final and static. d. All variables are static and methods are public if interface is defined public. Ans: (d) 42. Which one is correct declaration for implementing two interfaces? a. class C implements A, B { } b.

class C implements A, implements B { }

c. class C implements A extends B { } d. class C extend A, B { } Ans: (a) 43. The fields in an interface are implicitly specified as a. public b.

protected

c. private d. static and final Ans: (d)

12

Multiple Choice Questions Bank

OOP 1 3140705

44. Let us consider the following piece of code in Java. interface A

{ inti = 111;

} class B implements A { void i

methodB() {

= 222;

System.out.printl(i); } } What will be the result of this code will be? a. There is no main () method so the program is not executable. b.

The value of i will be printed as 111, as it is static and final by default.

c. The value of i will be printed as 222, as it is initialized in class B. d. Compile time error Ans: (d) 45. If a class inheriting an abstract class does not define all of its methods, then it will be known as a. Abstract class. b.

A normal class.

c. Final class d. An interface Ans: (a) 46. Does a subclass inherit both member variables and methods? a. No—only member variables are inherited. b.

13

No—only methods are inherited.

Multiple Choice Questions Bank

OOP 1 3140705

c. Yes—both are inherited - but not those are declared as private. d. Yes—only the members/ methods with protected are inherited. Ans: (c) 47. Can an object subclass another object? a. Yes—as long as single inheritance is followed. b.

No—inheritance is only between classes.

c. Only when one has been defined in terms of the other. d. Yes—when one object is used in the constructor of another. Ans: (b) 48. What is the output for the following Java program? class Base { public void show() { System.out.println("Base show() called"); } } class Derived extends Base { public void show() { System.out.println("Derived show() called"); } } public class Main { public void show() { System.out.println("Main show() called"); }

14

Multiple Choice Questions Bank

OOP 1 3140705

public static void main(String[ ] args) { Base bb = new Derived();; bb.show(); } } a. Base show() called b.

Main show() called

c. Derived show() called d. Compile time error Ans: (c) 49. Which of the following option leads to the portability and security of Java? a. Bytecode is executed by JVM b.

The applet makes the Java code secure and portable

c. Use of exception handling d. Dynamic binding between objects Ans: (a) 50. Which of the following is not a Java features? a. Dynamic b.

Architecture Neutral

c. Use of pointers d. Object-oriented Ans: (c) 51.

is used to find and fix bugs in the Java programs. a. JVM b.

JRE

c. JDK

15

Multiple Choice Questions Bank

OOP 1 3140705

d. JDB Ans: (d) 52. What is the return type of the hashCode() method in the Object class? a. object b.

int

c. long d. void Ans: (b) 53. Evaluate the following Java expression, if x=3, y=5, and z=10: ++z + y - y + z + x++ a. 24 b.

23

c. 20 d. 25 Ans: (a) 54. Which of the following for loop declaration is not valid? a. for ( int i = 99; i >= 0; i / 9 ) b. for ( int i = 7; i = 2; - -i ) d. for ( int i = 2; i...


Similar Free PDFs