0% found this document useful (0 votes)
6 views5 pages

Java MCQs for Exam Preparation

The document contains multiple-choice questions (MCQs) related to Java programming, covering topics such as exception handling, streams, inheritance, and object creation. Each question is followed by four options and the correct answer is provided. The questions test knowledge on Java's features, data types, and programming concepts.

Uploaded by

kajunew000
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)
6 views5 pages

Java MCQs for Exam Preparation

The document contains multiple-choice questions (MCQs) related to Java programming, covering topics such as exception handling, streams, inheritance, and object creation. Each question is followed by four options and the correct answer is provided. The questions test knowledge on Java's features, data types, and programming concepts.

Uploaded by

kajunew000
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

JAVA MCQs For Reference

1. Which keyword in Java is used to handle exceptions?


a) try
b) catch
c) throw
d) All of the above
Answer: d) All of the above
2. Which block is always executed whether an exception occurs or not?
a) try
b) catch
c) finally
d) throw
Answer: c) finally
3. Which keyword is used to explicitly throw an exception?
a) throws
b) throw
c) final
d) catch
Answer: b) throw

4. The statement throw new MyException("Error") is an example of:


a) Predefined exception
b) User-defined exception
c) Final block usage
d) Runtime error only
Answer: b) User-defined exception
5. In Java, a stream represents:
a) A sequence of data
b) A block of memory
c) A file pointer
d) None
Answer: a) A sequence of data
6. Which package provides file handling classes in Java?
a) [Link]
b) [Link]
c) [Link]
d) [Link]
Answer: c) [Link]
7. Which of the following is a byte stream class?
a) FileReader
b) FileWriter
c) FileInputStream
d) BufferedWriter
Answer: c) FileInputStream
8. Which classes are used for reading and writing text files?
a) FileReader & FileWriter
b) FileInputStream & FileOutputStream
c) Scanner & Formatter
d) None
Answer: a) FileReader & FileWriter
9. Character streams automatically handle:
a) Encoding and decoding
b) Only numbers
c) Binary data only
d) None
Answer: a) Encoding and decoding
10. Which of the following is true about streams?
a) Streams are bidirectional
b) Streams are unidirectional
c) Streams can only read data
d) Streams can only write data
Answer: b) Streams are unidirectional
11. To write text efficiently into a file, which class is best used?
a) FileOutputStream
b) FileWriter
c) BufferedWriter
d) PrintWriter
Answer: c) BufferedWriter

12. Which keyword is used to inherit a class in Java?


a) inherit
b) super
c) extends
d) implements
Answer: c) extends
13. Which type of inheritance is NOT supported directly in Java?
a) Single
b) Multilevel
c) Multiple
d) Hierarchical
Answer: c) Multiple
14. Which keyword is used to call a superclass constructor?
a) this
b) super
c) base
d) parent Answer: b) super
15. Method overriding requires:
a) Same method name
b) Same parameter list
c) Same return type
d) All of the above
Answer: d) All of the above
16. Which keyword is used to define an abstract method?
a) abstract
b) final
c) static
d) virtual
Answer: a) abstract

17. Which of the following is an example of hierarchical


inheritance? class A { }
class B extends A { }
class C extends A { }
a) Single
b) Multilevel
c) Hierarchical
d) Multiple
Answer: c) Hierarchical

1. Java is considered platform-independent because:


A) It uses pointers
B) Code is written in ASCII
C) Bytecode can run on any system with JVM
D) It uses assembly code
Answer: C
2. Which one of these is not a Java data type?
A) int
B) float
C) boolean
D) real
Answer: D
3. Which Java feature promotes reusability?
A) Encapsulation
B) Inheritance
C) Polymorphism
D) Abstraction
Answer: B
4. Which keyword is used to create an object in Java?
A) class
B) new
C) create
D) object
Answer: B
5. Which of the following is true about Java arrays?
A) They can hold elements of different data types
B) Their size is fixed once declared
C) They are not objects
D) Indexing starts from 1
Answer: B
6. What will `[Link](10 + 20 + "Hello");` output?
A) 30Hello
B) Hello30
C) 1020Hello
D) Hello1020
Answer: A
7. Java was developed by:
A) Microsoft
B) Google
C) Sun Microsystems
D) Oracle
Answer: C
8. What will the following code output? `int x = 10; if(x < 5) [Link]("Low"); else
[Link]("High");`
A) Low
B) High
C) Error
D) Nothing
Answer: B
9. What is the output of this code snippet? `int i=1; while(i<=3){ [Link](i); i++; }`
A) 123
B) 321
C) 111
D) 0
Answer: A
10. Which statement is used to skip the current iteration in a loop?
A) break
B) continue
C) return
D) exit
Answer: B
11. Which keyword is used in switch-case to exit from the case?
A) exit
B) quit
C) break
D) stop
Answer: C
12. What happens if `break` is not used in switch-case?
A) Compile-time error
B) Only the matched case executes
C) All following cases will execute
D) Program will crash
Answer: C
13. Which statement is used for multiple branching?
A) if
B) if-else
C) switch
D) continue
Answer: C
14. What is the correct way to create an object of class `Student`?
A) Student s = Student();
B) Student s = new Student();
C) Student s();
D) Student s = object();
Answer: B
15. What is method overriding?
A) Same method signature in superclass and subclass
B) Same class with different methods
C) Overloading the constructor
D) Rewriting methods in the same class
Answer: A

You might also like