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

Oop Using Java Mid Exam Question Bank

The document contains multiple-choice questions and fill-in-the-blank questions related to Java programming concepts, including platform independence, JVM, access modifiers, and object-oriented principles. It also discusses the significance of Java's object-oriented nature, differences between Java and C/C++, and the role of the Scanner class. Additionally, it covers topics like constructor overloading, method overloading, and the treatment of arrays as objects in Java.

Uploaded by

sathvikkummari6
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views8 pages

Oop Using Java Mid Exam Question Bank

The document contains multiple-choice questions and fill-in-the-blank questions related to Java programming concepts, including platform independence, JVM, access modifiers, and object-oriented principles. It also discusses the significance of Java's object-oriented nature, differences between Java and C/C++, and the role of the Scanner class. Additionally, it covers topics like constructor overloading, method overloading, and the treatment of arrays as objects in Java.

Uploaded by

sathvikkummari6
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

(I) Multiple Choice Questions

1. Which feature of Java ensures that a program can run on different platforms without
recompilation?
a) Dynamic Binding
b) Robustness
c) Platform Independence
d) Multithreading

Answer: c) Platform Independence

2. Which component of Java is responsible for converting bytecode into machine-specific


instructions at runtime?
a) JDK
b) JRE
c) JVM
d) JIT Compiler

Answer: c) JVM

3. Which Java primitive type occupies the highest memory?


a) int
b) float
c) double
d) long

Answer: c) double

4. Which operator is used to compare object references rather than object content?
a) equals()
b) ==
c) compareTo()
d) instanceof

Answer: b) ==

5. Which access modifier allows visibility only within the same package?
a) private
b) protected
c) public
d) default

Answer: d) default

6. Constructor overloading in Java is achieved using:


a) Different return types
b) Different access modifiers
c) Different parameter lists
d) Static constructors

Answer: c) Different parameter lists

7. Which keyword prevents method overriding?


a) static
b) final
c) private
d) protected

Answer: b) final

8. Which class is the direct superclass of all Java classes?


a) Class
b) System
c) Object
d) Main

Answer: c) Object

9. Which array stores elements in contiguous memory locations?


a) Jagged array
b) Dynamic array
c) One-dimensional array
d) Collection

Answer: c) One-dimensional array

10. Which class allows modification of string content without creating a new object?
a) String
b) StringTokenizer
c) StringBuffer
d) Character

Answer: c) StringBuffer

(II) Fill in the Blanks

(Answers are shown after the questions for evaluation)

11. ________ converts Java source code into bytecode.


Answer: javac

12. The logical AND operator in Java is represented by ________.


Answer: &&

13. The keyword used to create an object in Java is ________.


Answer: new

14. A constructor having the same name as the class and no return type is called a
________.
Answer: default constructor

15. Variables declared inside a method are known as ________ variables.


Answer: local

16. The ________ class is used to break a string into tokens.


Answer: StringTokenizer

17. Wrapper classes convert primitive data types into ________ types.
Answer: object

18. The ________ keyword is used to read input from the keyboard using Scanner.
Answer: [Link]

19. Arrays in Java are ________ indexed.


Answer: zero

20. The package that contains Scanner class is ________.


Answer: [Link]

1. write about history of java.


2. Differentiate between local variables and instance variables in Java.

Local variables are declared inside methods or blocks and are accessible only within that
scope. Instance variables are declared inside a class but outside methods and belong to an
object. Local variables must be initialized before use, whereas instance variables get default
values. Instance variables represent object state, while local variables support temporary
computations.

3. Explain constructor overloading with an example scenario.

Constructor overloading allows a class to have multiple constructors with different


parameter lists. It enables flexible object initialization. For example, a Student class can have
one constructor accepting name and another accepting name and roll number. This
improves usability and readability. Constructors are selected at compile time based on
arguments passed.

4. Describe the importance of access modifiers in Java.

Access modifiers control the visibility of classes, variables, and methods. They help achieve
encapsulation and data hiding. Private restricts access within a class, protected allows
subclass access, default permits package-level access, and public allows global access.
Proper use enhances security and maintainability.

5. Explain how String differs from StringBuffer.

String objects are immutable, meaning their values cannot be changed after creation.
StringBuffer objects are mutable and allow modification without creating new objects.
StringBuffer is thread-safe, whereas String is not. For frequent string manipulation,
StringBuffer offers better performance.

(I) Multiple Choice Questions

1. Which Java feature supports execution of multiple tasks simultaneously?


a) Robustness
b) Multithreading
c) Encapsulation
d) Inheritance

Answer: b) Multithreading
2. Which tool is required to compile a Java program?
a) JVM
b) JRE
c) JDK
d) JIT

Answer: c) JDK

3. Which primitive data type stores a single Unicode character?


a) byte
b) char
c) boolean
d) short

Answer: b) char

4. Which operator is used for conditional execution?


a) ::
b) ?:
c) &&
d) instanceof

Answer: b) ?:

5. Which keyword is used to prevent inheritance?


a) static
b) final
c) private
d) abstract

Answer: b) final

6. Which method is automatically invoked when an object is created?


a) main()
b) init()
c) constructor
d) finalize()

Answer: c) constructor
7. Which class provides methods for mathematical operations?
a) Math
b) System
c) Object
d) Number

Answer: a) Math

8. Which array type allows rows of different sizes?


a) Static array
b) One-dimensional array
c) Jagged array
d) Vector

Answer: c) Jagged array

9. Which wrapper class converts int to object?


a) Double
b) Integer
c) Float
d) Character

Answer: b) Integer

10. Which method compares two string values?


a) ==
b) equals()
c) compare()
d) match()

Answer: b) equals()

(II) Fill in the Blanks

11. The Java compiler generates ________ files after compilation.


Answer: bytecode

12. The ________ operator checks both condition and execution.


Answer: &&
13. Instance variables are stored in ________ memory.
Answer: heap

14. The class used for reading integer input is ________.


Answer: Scanner

15. The base class of all wrapper classes is ________.


Answer: Number

16. A block of code that initializes objects is called ________.


Answer: constructor

17. Java arrays are objects stored in ________.


Answer: heap

18. The package automatically imported in Java is ________.


Answer: [Link]

19. String objects are ________ in nature.


Answer: immutable

20. The method used to get input from Scanner is ________.


Answer: next()

1. Explain the significance of Java being an object-oriented language.

Java follows object-oriented principles like encapsulation, inheritance, polymorphism, and


abstraction. These principles help in organizing code efficiently. Objects represent real-world
entities, making programs easier to understand. OOP improves code reusability and
maintainability. Java enforces OOP concepts strictly.

2. Describe how Java differs from C and C++.

Java is platform-independent, whereas C and C++ are platform-dependent. Java does not
support pointers directly, improving security. Memory management in Java is automatic
through garbage collection. Java supports multithreading inherently. C++ allows multiple
inheritance, while Java avoids ambiguity using interfaces.

3. Explain method overloading with a suitable example.

Method overloading allows multiple methods with the same name but different parameter
lists. It improves code readability and reusability. The compiler decides which method to
invoke based on arguments. Overloading can differ in number or type of parameters. Return
type alone cannot distinguish overloaded methods.

4. Discuss the role of Scanner class in Java.


Scanner class is used to read input from the keyboard. It belongs to [Link] package. It
supports reading different data types like int, float, and String. Scanner improves user
interaction in console applications. It simplifies parsing input data.

5. Explain arrays as objects in Java.

Arrays in Java are treated as objects stored in heap memory. They have a fixed size and store
elements of the same data type. Arrays support indexing and length property. They simplify
data storage and access. Java provides bounds checking to prevent runtime errors.

You might also like