KEMBAR78
OOPC I - Model Paper | PDF | Class (Computer Programming) | Variable (Computer Science)
0% found this document useful (0 votes)
13 views10 pages

OOPC I - Model Paper

The document is a model paper for an Object-Oriented Programming Concepts (OOPC) exam, consisting of multiple-choice questions covering various Java programming topics. It includes questions on Java syntax, data types, control structures, object-oriented principles, memory management, and exceptions. Each question provides four answer options, with a focus on assessing knowledge of Java programming fundamentals.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views10 pages

OOPC I - Model Paper

The document is a model paper for an Object-Oriented Programming Concepts (OOPC) exam, consisting of multiple-choice questions covering various Java programming topics. It includes questions on Java syntax, data types, control structures, object-oriented principles, memory management, and exceptions. Each question provides four answer options, with a focus on assessing knowledge of Java programming fundamentals.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

OOPC I – Model Paper

PART A

1. Which is the correct signature of the main method in Java?


A. public static void main(String args)
B. public void main(String[] args)
C. public static void main(String[] args)
D. static public void main(String args)

2. Which variables are shared among all instances of a class?


A. Local variables
B. Instance variables
C. Static variables
D. Reference variables

3. Which of the following is NOT a valid Java identifier?


A. myVariable
B. _counter
C. 2ndValue
D. $amount

4. Which modifier makes a variable accessible only within the same class?
A. public
B. private
C. protected
D. default

5. Which statement is correct about instance variables?


A. They are declared inside methods
B. Each object has its own copy
C. They must be static
D. They cannot have default values

6. Which is true about objects in Java?


A. Objects are created using new keyword
B. Objects are primitive data types
C. Objects do not consume memory
D. Objects cannot be passed as arguments
7. What is the output of the following code?
int x = 5;
x += 3;
System.out.println(x);

A. 3
B. 53
C. 8
D. 5

8. What does the following code snippet print?


int x = 11;
x %= 6;
System.out.println(x);

A. 1
B. 1.8
C. 4
D. 5

9. Which of the following correctly tests if an object obj is an instance of class String?
A. if(obj.equals(String))
B. if(obj == String)
C. if(obj instanceof String)
D. if(obj.instanceOf(String))

10. What is the result of the following code?


int a = 10, b = 20;
boolean result = (a > 5) && (b < 25);
System.out.println(result);

A. true
B. false
C. 30
D. 20

11. Which operator is used for short-circuit logical OR?


A. |
B. ||
C. &
D. &&
12. What is the output?
int x = 5, y = 10; System.out.println(x == y);

A. 5
B. 10
C. True
D. false

13. Which of the following is a Java operator?


A. %
B. ()
C. {}
D. ;

14. What does the following code snippet print?


int i = 0;
System.out.println(i++);

A. a. 0
B. b. 1
C. c. 2
D. d. 3

15. What will be the output of this code?


int x = 10; if (x > 5){
System.out.println("A");
} else {
System.out.println("B");
}

A. A
B. B
C. Compile-time error
D. No output

16. Which loop will always execute at least once?


A. For
B. While
C. do-while
D. foreach
17. What is the output?
int i = 0;
while(i < 3){
System.out.print(i); i++;
}

A. 012
B. 0123
C. 123
D. Infinite loop

18. What does the break statement do?


A. Ends the current loop immediately
B. Skips the current iteration
C. Ends the program
D. Pauses execution

19. Which of the following is a valid labeled statement in Java?


A. outer: for(int i=0;i<5;i++) { }
B. label i: for(int i=0;i<5;i++) { }
C. inner label: for(int i=0;i<5;i++) { }
D. loop: if(true) { }

20. What is the output?


int day = 3;
switch(day){
case 1: System.out.print("Mon");
break;
case 2: System.out.print("Tue");
break;
case 3: System.out.print("Wed");
break;
default: System.out.print("Other");
}

A. Mon
B. WedOther
C. Wed
D. Other
21. Which keyword is used to inherit a class in Java?
A. Implements
B. Extends
C. Super
D. Inherit

22. Inheritance in Java represents a/an ____________relationship.


A. HAS-A
B. IS-A
C. CAN-DO
D. USES-A

23. Which of the following best represents a HAS-A relationship?


A. class Car extends Vehicle
B. class Car { Engine e; }
C. class Car implements Drivable
D. class Car inherits Vehicle

24. Which of these supports runtime polymorphism in Java?


A. Method overloading
B. Method overriding
C. Constructor overloading
D. Final methods

25. Abstract classes in Java can:


A. Have constructors
B. Be instantiated directly
C. Only have abstract methods
D. Not contain variables

26. Which concept allows one interface to be used for different underlying data types?
A. Encapsulation
B. Abstraction
C. Polymorphism
D. Association

27. Which is true about abstraction?


A. Hides implementation details
B. Hides data using private variables
C. Always uses final classes
D. Is the same as encapsulation
28. Aggregation represents:
A. Weak HAS-A relationship
B. Strong HAS-A relationship
C. IS-A relationship
D. No relationship

29. Which code is used to override a superclass method?


A. Override
B. extends
C. @Override annotation
D. super

30. Encapsulation in Java is achieved mainly by:


A. Abstract classes
B. Access modifiers (private/public)
C. Inheritance
D. Method overloading

31. Method overloading is based on:


A. Same method name, different parameters
B. Same method name, same parameters
C. Same return type only
D. Inheritance only

32. Which of the following is used to handle exceptions in Java?


A. try-catch
B. if-else
C. switch-case
D. for-loop

33. What is the default constructor?


A. A constructor with no parameters
B. A constructor with parameters
C. A private constructor
D. An abstract constructor

34. Which of the following is true about overloaded constructors?


A. They must have different names
B. They must have different parameter lists
C. They must have different return types
D. They must be static
35. Which access modifier makes a member accessible only within the same package?
A. private
B. protected
C. public
D. default (package-private)

36. What does the 'static' keyword mean in Java?


A. The member belongs to the instance
B. The member belongs to the class
C. The member cannot be accessed
D. The member is abstract

37. Which of these can have both abstract methods and implemented methods?
A. Class
B. Interface (before Java 8)
C. Abstract class
D. Both b and c

38. Which statement is correct?


A. Interfaces can extend multiple interfaces
B. A class can extend multiple classes
C. Abstract class must have only abstract methods
D. Final class can be inherited

39. Which method is called when an object is created?


A. main()
B. Constructor
C. finalize()
D. toString()

40. What is the output of the following code?


String s1 = "Hello";
String s2 = "Hello";
System.out.println(s1 == s2);

A. true
B. false
C. Compilation error
D. Runtime error
41. Which of the following is widening conversion in Java?
A. int into double
B. double into int
C. long into int
D. char into byte

42. Which conversion requires explicit casting?


A. byte into int
B. int into long
C. double into float
D. char into int

43. What is the output?


int x = (int) 9.7;
System.out.println(x);

A. 9.7
B. 10
C. 9
D. Error

44. Which of these correctly declares an array?


A. int arr[];
B. int[] arr;
C. int arr[] = new int[5];
D. All of the above

45. What is the index of the first element in a Java array?


A. 1
B. 0
C. -1
D. Depends on array type

46. Which will correctly construct an array of 5 integers?


A. int arr = new int(5);
B. int arr[] = new int[5];
C. int arr[5];
D. int arr() = new int[5];

47. What happens if you access arr[10] in an array of size 5?


A. Returns null
B. Compile-time error
C. Throws ArrayIndexOutOfBoundsException
D. Returns garbage value
48. What is the output?
int[] arr = {1,2,3};
System.out.println(arr.length);

A. 2
B. 3
C. 4
D. Error

49. Which method is called by the garbage collector before reclaiming memory?
A. finalize()
B. destructor()
C. dispose()
D. delete()

50. In Java, garbage collection is:


A. Manual
B. Automatic
C. Both manual and automatic
D. Not supported

51. Which keyword can be used to suggest garbage collection?


A. finalize
B. gc()
C. System.gc()
D. clean()

52. Which of the following is NOT a feature of Java?


A. Platform independence
B. Automatic memory management
C. Multiple inheritance with classes
D. Object-oriented programming

53. Which statement about Java’s memory management is true?


A. Programmer must free memory manually
B. JVM handles memory management automatically
C. Objects are always destroyed immediately after use
D. Memory leaks cannot happen in Java

54. Which reference type allows objects to be garbage-collected even when referenced?
A. Strong Reference
B. Weak Reference
C. Static Reference
D. Constant Reference
55. Which JVM memory area stores objects?
A. Stack
B. Heap
C. Registers
D. Method area

56. What will be the output of the following code?


int a = 5;
System.out.println(a++ + ++a);

A. 10
B. 11
C. 12
D. 13

57. What is printed?


String[] s = new String[2]; System.out.println(s[0]);

A. ""
B. null
C. Error
D. ""

58. Which is true about arrays in Java?


A. They are objects
B. They are primitive types
C. They cannot store objects
D. Their size can change dynamically

59. Which keyword is used to prevent a method from being overridden?


A. final
B. static
C. const
D. abstract

60. What is the default value of a boolean instance variable in Java?


A. true
B. false
C. 0
D. null

You might also like