Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views18 pages

MPPSC Java Mcqs Part II

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)
3 views18 pages

MPPSC Java Mcqs Part II

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/ 18

1.

Which of the following is not a feature of Object-Oriented Programming in


Java?

A. Encapsulation​
B. Inheritance​
C. Compilation​
D. Polymorphism

Answer: C. Compilation​
Explanation: Compilation is a general programming concept, not an OOP feature.

2. Which keyword is used to create an object in Java?

A. class​
B. new​
C. object​
D. void

Answer: B. new​
Explanation: The new keyword is used to create objects in Java.

3. Which of the following control statements is used to make decisions in


Java?

A. for​
B. switch​
C. do​
D. while
Answer: B. switch​
Explanation: switch allows branching based on different values.

4. Java supports which of the following loop constructs?

A. repeat-until​
B. for​
C. foreach​
D. repeat

Answer: B. for​
Explanation: Java supports for, while, and do-while.

5. A block of code in Java is enclosed within:

A. ( )​
B. < >​
C. [ ]​
D. { }

Answer: D. { }​
Explanation: { } denotes a block in Java.

6. Which statement is true about Java blocks?

A. Only used in methods​


B. Cannot be nested​
C. Used in classes, methods, and static blocks​
D. Do not exist
Answer: C. Used in classes, methods, and static blocks​
Explanation: Java allows block-level scoping and nesting.

7. Which is a valid Java identifier?

A. 1value​
B. _count​
C. class​
D. @name

Answer: B. _count​
Explanation: Identifiers can't start with digits or contain symbols like @.

8. What are Java tokens?

A. Memory units​
B. Compilation errors​
C. Smallest units of a program​
D. External libraries

Answer: C. Smallest units of a program​


Explanation: Tokens include keywords, literals, identifiers, and operators.

9. What symbol is used for single-line comments in Java?

A. //​
B. /*​
C. #​
D. %%

Answer: A. //​
Explanation: // starts a single-line comment in Java.

10. Java class library java.util is mainly used for:

A. Input/output​
B. Networking​
C. Data structures and utilities​
D. Graphics

Answer: C. Data structures and utilities​


Explanation: It includes collections like ArrayList, HashMap, etc.

11. Which control statement is used to exit a loop early?

A. skip​
B. break​
C. continue​
D. return

Answer: B. break​
Explanation: break exits the nearest loop immediately.

12. Which of these is a looping control statement in Java?


A. switch​
B. goto​
C. while​
D. label

Answer: C. while​
Explanation: while is used to execute a loop based on a condition.

13. Which of these is used to skip an iteration of a loop?

A. exit​
B. break​
C. continue​
D. return

Answer: C. continue​
Explanation: continue skips the current iteration of the loop.

14. What is the default package imported in every Java program?

A. java.io​
B. java.util​
C. java.lang​
D. java.net

Answer: C. java.lang​
Explanation: This includes core classes like String, System, etc.
15. What is the file extension of a compiled Java class?

A. .java​
B. .exe​
C. .obj​
D. .class

Answer: D. .class​
Explanation: Java bytecode is stored in .class files.

16. Java programs are first compiled into:

A. Machine code​
B. Bytecode​
C. Binary code​
D. Object code

Answer: B. Bytecode​
Explanation: Java uses JVM which interprets bytecode.

17. What is the output of System.out.println(5 + 6);?

A. 11​
B. "11"​
C. 5 + 6​
D. Compilation error

Answer: A. 11​
Explanation: It prints the sum of 5 and 6.
18. The main method signature in Java is:

A. static void main()​


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

Answer: C. public static void main(String[] args)​


Explanation: It's the standard entry point.

19. Which keyword is used to inherit a class?

A. inherit​
B. extends​
C. implements​
D. derived

Answer: B. extends​
Explanation: extends is used for class inheritance.

20. Which keyword is used for implementing interfaces?

A. implements​
B. interface​
C. inherit​
D. override
Answer: A. implements​
Explanation: A class implements an interface using implements.

21. What is the super class of all Java classes?

A. java.lang.Class​
B. java.lang.Object​
C. java.lang.Base​
D. java.Class

Answer: B. java.lang.Object​
Explanation: All Java classes directly or indirectly inherit from Object.

22. Which of the following is a primitive data type in Java?

A. String​
B. boolean​
C. ArrayList​
D. Object

Answer: B. boolean​
Explanation: Java has 8 primitive types like int, char, boolean, etc.

23. Which of these is not a control structure in Java?

A. if​
B. loop​
C. switch​
D. for
Answer: B. loop​
Explanation: loop is not a keyword or statement in Java.

24. Java supports multiple inheritance via:

A. Classes only​
B. Interfaces only​
C. Abstract classes​
D. Packages

Answer: B. Interfaces only​


Explanation: Java avoids ambiguity by allowing multiple inheritance only via
interfaces.

25. Which of these is not a Java keyword?

A. static​
B. this​
C. implement​
D. synchronized

Answer: C. implement​
Explanation: The correct keyword is implements.

26. What does the keyword this refer to?


A. Static context​
B. Current class​
C. Super class​
D. None

Answer: B. Current class​


Explanation: this refers to the current object.

27. What is System.out in Java?

A. A method​
B. A variable​
C. A class​
D. A static object

Answer: D. A static object​


Explanation: It is a static PrintStream object of the System class.

28. Which loop checks the condition after executing?

A. for​
B. while​
C. do-while​
D. foreach

Answer: C. do-while​
Explanation: It guarantees one execution before condition checking.
29. Lexical analysis in Java refers to:

A. Type checking​
B. Parsing​
C. Breaking code into tokens​
D. Optimizing code

Answer: C. Breaking code into tokens​


Explanation: This phase identifies keywords, literals, and identifiers.

30. Which keyword prevents inheritance?

A. abstract​
B. static​
C. final​
D. super

Answer: C. final​
Explanation: final class cannot be extended.

31. What is the role of JVM?

A. Compiles code​
B. Converts bytecode to machine code​
C. Writes code​
D. Manages databases

Answer: B. Converts bytecode to machine code​


Explanation: JVM runs the bytecode on the native machine.
32. What will happen if no main method is defined in a class?

A. Runtime error​
B. Compilation error​
C. Infinite loop​
D. Program runs fine

Answer: A. Runtime error​


Explanation: Java needs main() as entry point.

33. Which keyword is used to create a constant variable?

A. static​
B. const​
C. final​
D. define

Answer: C. final​
Explanation: final makes a variable immutable.

34. A package is used to:

A. Import libraries​
B. Group related classes​
C. Run Java programs​
D. Secure code

Answer: B. Group related classes​


Explanation: Packages organize classes in namespaces.
35. Which class allows input from keyboard?

A. Scanner​
B. InputStream​
C. Console​
D. FileReader

nswer: A. Scanner​
Explanation: Scanner class is used with System.in.

36. What is true about Java exception handling?

A. It’s not supported​


B. Only one catch per try​
C. Multiple catch blocks allowed​
D. try block is optional

Answer: C. Multiple catch blocks allowed​


Explanation: You can handle different exceptions using multiple catch blocks.

37. Which of the following is used to declare a class?

A. class​
B. Class​
C. CLASS​
D. declare
nswer: A. class​
Explanation: Java is case-sensitive; class is the correct keyword.

38. Java bytecode is:

A. Hardware dependent​
B. Platform independent​
C. OS dependent​
D. Non-portable

Answer: B. Platform independent​


Explanation: Bytecode runs on any JVM regardless of OS.

39. What does the super keyword refer to?

A. Current object​
B. Current method​
C. Parent class​
D. Static context

Answer: C. Parent class​


Explanation: super is used to access parent class methods/constructors.

40. Which package provides classes for event handling?

A. java.io​
B. java.awt.event​
C. java.lang.event​
D. java.util.event
nswer: B. java.awt.event​
Explanation: Used for GUI event handling.

41. Which loop is ideal when number of iterations is known?

A. while​
B. do-while​
C. for​
D. switch

Answer: C. for​
Explanation: for is concise and ideal for definite loops.

42. Java library for file operations is:

A. java.io​
B. java.nio​
C. java.file​
D. java.input

Answer: A. java.io​
Explanation: Contains classes like File, FileReader, BufferedReader.

43. What does JVM stand for?

A. Java Variable Machine​


B. Java Virtual Machine​
C. Java Verification Method​
D. Java Version Machine

Answer: B. Java Virtual Machine​


Explanation: JVM runs compiled bytecode.

44. Which access modifier allows access within the same package only?

A. public​
B. private​
C. protected​
D. default

Answer: D. default​
Explanation: No modifier means package-private access.

45. Which of the following is a valid if statement?

A. if x > 10​
B. if (x > 10)​
C. if x => 10​
D. if x = 10

Answer: B. if (x > 10)​


Explanation: The condition must be in parentheses.

46. Java source code file extension is:


A. .jav​
B. .jv​
C. .java​
D. .class

Answer: C. .java​
Explanation: The compiler compiles .java files to .class.

47. Which of these can be overloaded in Java?

A. Constructors​
B. Packages​
C. Interfaces​
D. Keywords

Answer: A. Constructors​
Explanation: You can define multiple constructors with different parameters.

48. Which operator is used for string concatenation?

A. &​
B. +​
C. *​
D. %

nswer: B. +​
Explanation: The + operator is used to concatenate strings.

49. Which class is used to read a line of input in Java?


A. StringReader​
B. FileInputStream​
C. Scanner​
D. BufferedReader

Answer: D. BufferedReader​
Explanation: BufferedReader can read a line via readLine().

50. Which statement ends the execution of a method?

A. break​
B. continue​
C. return​
D. stop

Answer: C. return​
Explanation: return exits the method and optionally returns a value.

You might also like