Who developed the Java programming language?
A. Dennis Ritchie
B. Bjarne Stroustrup
C. James Gosling
D. Guido van Rossum
Answer: C. James Gosling
2. Which of the following is not a Java feature?
A. Object-Oriented
B. Use of pointers
C. Platform Independent
D. Robust
Answer: B. Use of pointers
3. The extension of compiled Java classes is:
A. .java
B. .class
C. .exe
D. .jar
Answer: B. .class
4. The component responsible for converting bytecode into machine code at runtime is:
A. JDK
B. JVM
C. JRE
D. JIT
Answer: B. JVM
5. JDK stands for:
A. Java Deployment Kit
B. Java Development Kit
C. Java Debugging Kit
D. Java Distribution Kit
Answer: B. Java Development Kit
6. The correct structure of a Java program is:
A. Class → Method → Package
B. Package → Method → Class
C. Class → Package → Method
D. Package → Class → Method
Answer: D. Package → Class → Method
7. The keyword used to define a class in Java is:
A. define
B. class
C. struct
D. object
Answer: B. class
8. The default value of a boolean variable in Java is:
A. true
B. false
C. 0
D. null
Answer: B. false
9. The following is not a valid data type in Java:
A. int
B. float
C. real
D. char
Answer: C. real
10. The size of int in Java is:
A. 2 bytes
B. 4 bytes
C. 8 bytes
D. Depends on OS
Answer: B. 4 bytes
11. Example of implicit type casting:
A. double x = 10;
B. int y = (int) 10.5;
C. float z = (float) 20;
D. None of the above
Answer: A. double x = 10;
12. Operator used to compare two values:
A. =
B. ==
C. :=
D. ===
Answer: B. ==
13. The output of the following code:
int x = 10;
if (x > 5)
[Link]("Greater");
else
[Link]("Smaller");
A. Greater
B. Smaller
C. Error
D. None of the above
Answer: A. Greater
14. Loop guaranteed to execute at least once:
A. for
B. while
C. do...while
D. foreach
Answer: C. do...while
15. The break statement in a loop:
A. Skips current iteration
B. Stops entire loop
C. Continues next iteration
D. Exits program
Answer: B. Stops entire loop
Long Answer Questions (with outlines)
1. Explain the features of Java.
2. What is Java Virtual Machine (JVM)? Describe its role.
3. Explain the folder structure of JDK and its components.
4. Describe the control structures used in Java. Explain Branching Statements with examples.
5. Describe the control structures used in Java. Explain Looping (Iterative) Statements with
examples.
6. Type casting
Java: Introducing Classes and Objects –
1. A class in Java is:
A) A variable
B) A method
C) A blueprint for objects
D) A data type
✔ Answer: C
2. An object is:
A) A data type
B) An instance of a class
C) A package
D) A method
✔ Answer: B
3. A method that belongs to a class and not an object is declared with the keyword:
A) abstract
B) void
C) static
D) final
✔ Answer: C
4. Access specifier that allows access from any class:
A) private
B) protected
C) default
D) public
✔ Answer: D
5. A constructor:
A) Must have a return type
B) Is called when an object is created
C) Can be abstract
D) Can be static
✔ Answer: B
6. When two or more constructors exist in the same class with different parameters, it is
known as:
A) Constructor chaining
B) Constructor overriding
C) Constructor inheritance
D) Constructor overloading
✔ Answer: D
7. The keyword this refers to:
A) Current object
B) Parent class
C) Static variable
D) Constructor
✔ Answer: A
8. The default constructor is:
A) A constructor with parameters
B) Provided by the user
C) Provided by Java if no constructor is defined
D) Always private
✔ Answer: C
9. Method overloading is:
A) Using same method name with different parameters
B) Inheriting methods
C) Defining a method in a subclass
D) Changing method body only
✔ Answer: A
10. The finalize() method is used:
A) To initialize variables
B) To terminate program
C) For garbage collection cleanup
D) To start threads
✔ Answer: C
11. A wrapper class for the primitive int is:
A) Integer
B) Int
C) Number
D) Double
✔ Answer: A
12. Arrays in Java are:
A) Objects
B) Methods
C) Interfaces
D) Keywords
✔ Answer: A
13. A collection class that allows random access and dynamic resizing:
A) LinkedList
B) Vector
C) ArrayList
D) Stack
✔ Answer: C
14. Interface used to iterate over collections:
A) Iterator
B) List
C) Collection
D) Iterable
✔ Answer: A
15. Follows Last-In-First-Out (LIFO) order:
A) Queue
B) Stack
C) LinkedList
D) ArrayList
✔ Answer: B
Short Answer Questions
1. What is a class in Java?
2. What is method overloading?
3. What is a constructor?
4. What is an array of objects?
Long Answer Question
Describe how to define a class in Java. Explain field declaration and method declaration with suitable
examples.
Define constructors in Java. Explain different types of constructors and the concept of constructor
overloading with examples.
Describe arrays in Java. What are the different types of arrays? How can you create and use an array
of objects?
What is the use of the this keyword in Java? Illustrate its different uses with examples.
Inheritance, Packages, and Interfaces — 15 MCQs
The keyword used to inherit a class in Java is:
A) this
B) super
C) extends
D) implements
Answer: C
Java supports multiple inheritance through:
A) Classes
B) Interfaces
C) Packages
D) None of the above
Answer: B
Method overriding occurs when a subclass defines a method with:
A) The same name and parameters as the superclass method
B) The same name but different parameters
C) A different name
D) None of the above
Answer: A
The super keyword in Java is used to:
A) Call superclass constructor or method
B) Access static methods
C) Override methods
D) Refer to the current object
Answer: A
Dynamic method dispatch in Java refers to:
A) Compile-time polymorphism
B) Runtime polymorphism where method calls are resolved at runtime
C) Method overloading
D) Static binding
Answer: B
An abstract class can have:
A) Only abstract methods
B) Only concrete methods
C) Both abstract and concrete methods
D) None of the above
Answer: C
The final keyword in Java can be used to:
A) Prevent inheritance of a class
B) Prevent method overriding
C) Declare constants
D) All of the above
Answer: D
Interfaces in Java can contain:
A) Only abstract methods
B) Abstract methods and static/default methods
C) Only constants
D) Constructors
Answer: B
The keyword used by a class to implement an interface is:
A) extends
B) implements
C) import
D) interface
Answer: B
The package [Link] contains:
A) Input/output classes
B) Fundamental classes like String, Math, System
C) Collection framework classes
D) Networking classes
Answer: B
To define a package in a Java source file, the syntax is:
A) import packageName;
B) package packageName;
C) define packageName;
D) class packageName;
Answer: B
To use classes from another package, you use the keyword:
A) extends
B) import
C) implements
D) package
Answer: B
Which of the following is NOT a type of inheritance in Java?
A) Single inheritance
B) Multiple inheritance through classes
C) Multilevel inheritance
D) Hierarchical inheritance
Answer: B
The difference between method overloading and overriding is that:
A) Overloading is runtime polymorphism; overriding is compile-time polymorphism
B) Overriding occurs within the same class; overloading occurs in subclass
C) Overloading is compile-time polymorphism; overriding is runtime polymorphism
D) Both are the same
Answer: C
Which class among the following cannot be subclassed?
A) Abstract class
B) Final class
C) Interface
D) Static class
Answer: B
Long Answer Questions
1. Explain the concept of inheritance in Java. Describe its syntax and different types of
inheritance with examples.
2. What is method overriding? How is it different from method overloading? Illustrate with
examples.
3. Define abstract class and abstract method in Java. Explain their use and provide examples.
4. What is an interface in Java? Explain how to define and implement interfaces. How does Java
support multiple inheritance using interfaces?
5. What are packages in Java? Explain the purpose of packages and the steps to create and use
user-defined packages.
6. Describe the use of the super keyword in Java. How does it help in accessing superclass
members?
Short Answer Questions
1. What is inheritance in Java?
2. Define method overriding.
3. What is the use of the super keyword?
4. What is the difference between an abstract class and an interface?
5. How is multiple inheritance achieved in Java?
6. Name any two built-in Java packages.
Exception Handling and Multithreading in Java
The keyword used to handle exceptions in Java is:
A) try-catch
B) throw
C) exception
D) error
Answer: A
Which of the following is NOT an example of a checked exception?
A) IOException
B) ClassNotFoundException
C) NullPointerException
D) SQLException
Answer: C
The block that executes whether or not an exception occurs is:
A) catch
B) finally
C) throw
D) try
Answer: B
Which keyword is used to declare exceptions that a method can throw?
A) throw
B) throws
C) try
D) catch
Answer: B
User-defined exceptions in Java must extend which class?
A) Throwable
B) Error
C) Exception
D) RuntimeException
Answer: C
Which method is used to start a thread in Java?
A) run()
B) start()
C) execute()
D) init()
Answer: B
Which interface must a class implement to create a thread by implementing Runnable?
A) Runnable
B) Thread
C) Executor
D) Callable
Answer: A
The method that pauses the current thread for a specified time is:
A) yield()
B) suspend()
C) sleep()
D) wait()
Answer: C
Which method causes the currently executing thread to temporarily pause and allow other
threads to execute?
A) sleep()
B) yield()
C) wait()
D) notify()
Answer: B
Which of the following methods are deprecated and should be avoided?
A) stop() and suspend()
B) start() and run()
C) wait() and notify()
D) yield() and sleep()
Answer: A
What is the purpose of thread synchronization?
A) To allow threads to run independently
B) To avoid thread interference and memory consistency errors
C) To increase thread creation time
D) To pause threads permanently
Answer: B
Which keyword is used to define a synchronized block or method?
A) synchronized
B) lock
C) mutex
D) concurrent
Answer: A
What is the difference between checked and unchecked exceptions?
A) Checked exceptions are checked at runtime; unchecked are at compile time
B) Checked exceptions are checked at compile time; unchecked are at runtime
C) Both are checked at runtime
D) Both are checked at compile time
Answer: B
Which method resumes a suspended thread?
A) start()
B) resume()
C) run()
D) notify()
Answer: B
Which of the following is NOT true about the wait() method?
A) It releases the lock on the object
B) It must be called from a synchronized context
C) It wakes up a thread immediately
D) It causes the current thread to wait until notified
Answer: C
Long Answer Questions
1. Explain the concept of exceptions in Java. Differentiate between errors and exceptions
with examples.
2. Describe the types of exceptions in Java. What are checked and unchecked
exceptions? Provide examples.
3. How is exception handling done in Java using try and catch blocks? Explain with a
suitable example.
4. Define multithreading in Java. How does a thread differ from a process?
5. Explain the life cycle of a thread in Java. Illustrate with a diagram or description of
various thread states.
Short Answer Questions
1. What is an exception in Java?
2. Differentiate between error and exception.
3. What are checked exceptions? Give an example.
4. What are unchecked exceptions? Give an example.
5. How do you handle exceptions using try and catch blocks?