KEMBAR78
Suggestive MCQ Questions of JAVA | PDF | Object Oriented Programming | Class (Computer Programming)
0% found this document useful (0 votes)
21 views15 pages

Suggestive MCQ Questions of JAVA

The document contains suggestive multiple-choice questions (MCQs) for Java, organized into six units covering object-oriented design, concepts, basic programming, class and object properties, reusability, and exception handling. Each unit includes questions categorized by difficulty level: easy, moderate, and difficult, with correct answers provided. The content focuses on key Java programming principles, terminology, and functionalities.

Uploaded by

Tridib Bhunia
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)
21 views15 pages

Suggestive MCQ Questions of JAVA

The document contains suggestive multiple-choice questions (MCQs) for Java, organized into six units covering object-oriented design, concepts, basic programming, class and object properties, reusability, and exception handling. Each unit includes questions categorized by difficulty level: easy, moderate, and difficult, with correct answers provided. The content focuses on key Java programming principles, terminology, and functionalities.

Uploaded by

Tridib Bhunia
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/ 15

Suggestive MCQ questions of JAVA

UNIT-1:
Object-Oriented Design: Introduction to object-oriented programming languages, Major and
minor elements of OOP, Objects and classes, Relationships among objects and classes:
aggregation, association, instantiation, grouping constructs.
Easy Level:
1. What is an object in OOP?
A. A function
B. A variable
C. An instance of a class
D. A loop
Ans: C
2. What is a class in Java?
A. A built-in function
B. A user input
C. A blueprint for objects
D. A variable type
Ans: C
3. Which of the following is an example of a real-world object?
A. int
B. System
C. Dog
D. for loop
Ans: C
4. Which concept defines a "has-a" relationship?
A. Inheritance
B. Aggregation
C. Instantiation
D. Interface
Ans: B
5. Which relationship connects objects without ownership?
A. Aggregation
B. Association
C. Inheritance
D. Abstraction
Ans: B
Moderate Level:
6. Which of the following is a minor element in OOP?
A. Polymorphism
B. Object
C. Message Passing
D. Class
Ans: C
7. Aggregation is a type of:
A. Inheritance
B. Composition
C. Relationship
D. Instantiation
Ans: C
8. Which of the following is true about object-oriented design?
A. Focuses only on functions
B. Focuses on data and behavior encapsulation
C. Doesn't support reuse
D. Doesn't support modularity
Ans: B
9. A class is a:
A. Blueprint for objects
B. Memory location
C. Static method
D. Type of exception
Ans: A
Difficult Level:
10.Which of the following best describes “association” in OOP?
A. One object contains another
B. One object inherits another
C. Objects share a relationship without ownership
D. An object is a superclass
Ans: C
11.Which grouping construct allows treating multiple objects as a single unit?
A. Aggregation
B. Instantiation
C. Association
D. Package
Ans: A
12.In OOP, instantiation refers to:
A. Destroying an object
B. Copying an object
C. Creating an object from a class
D. Importing a class
Ans: C

UNIT-2:
Object-Oriented Concepts: Differences between OOP and conventional programming<
Advantages and disadvantages of OOP, Key OOP concepts: Class, Object, Message Passing,
Inheritance, Encapsulation, Polymorphism.
Easy Level:
1. Polymorphism means:
A. One object, many forms
B. Many classes, one object
C. Hiding data
D. Using super
Ans: A
2. Inheritance allows:
A. Copying objects
B. Code reuse
C. Hiding methods
D. None of the above
Ans: B
3. Which of the following hides the internal details?
A. Inheritance
B. Abstraction
C. Polymorphism
D. Overriding
Ans: B
4. Which keyword is used to create a class in Java?
A. class
B. Class
C. new
D. create
Ans: A
5. What does encapsulation protect?
A. The JVM
B. Data from unauthorized access
C. Loop execution
D. The screen output
Ans: B
Moderate Level:
6. Encapsulation is achieved using:
A. Inheritance
B. Private variables and public methods
C. Interfaces
D. Abstract classes only
Ans: B
7. Which of the following supports code reuse the most?
A. Encapsulation
B. Inheritance
C. Polymorphism
D. Message passing
Ans: B
8. Which of the following is a disadvantage of OOP?
A. Difficult to maintain code
B. Poor modularity
C. Slower performance in some cases
D. No reuse
Ans: C
9. Which of the following allows objects to interact?
A. Inheritance
B. Polymorphism
C. Message Passing
D. Abstraction
Ans: C
Difficult Level:
10.Which of the following is not a key concept of OOP?
A. Abstraction
B. Compilation
C. Encapsulation
D. Polymorphism
Ans: B
11.Which of the following violates encapsulation?
A. Declaring all data members public
B. Using getters/setters
C. Using private access modifier
D. Declaring data members protected
Ans: A
12.In OOP, polymorphism allows:
A. Multiple methods to have same name but different parameters
B. One class to extend another
C. Objects to be grouped
D. Classes to be static
Ans: A

UNIT-3:
Basic Concepts of Object-Oriented Programming Using Java: Implementation of OOP
concepts using Java, Introduction to Java programming language.
Easy Level:
1. Java is a:
A. Procedural language
B. Functional language
C. Object-Oriented language
D. Machine-level language
Ans: C
2. Which tool compiles Java code?
A. JVM
B. JDK
C. JRE
D. javac
Ans: D
3. Which of these is a Java keyword?
A. number
B. public
C. output
D. real
Ans: B
4. Which symbol is used to end a statement in Java?
A. :
B. .
C. ;
D. ,
Ans: C
5. Which keyword is used to create an object?
A. new
B. class
C. import
D. object
Ans: A
Moderate Level:
6. What is the file extension for compiled Java code?
A. .java
B. .exe
C. .class
D. .obj
Ans: C
7. Which is a valid Java identifier?
A. 1stValue
B. _value
C. class
D. new
Ans: B
8. Which of the following is a valid way to declare a main method?
A. void main(String[] args)
B. public void main(String args)
C. public static void main(String[] args)
D. static void main()
Ans: C
9. Which method is used to print output in Java?
A. console.log()
B. echo()
C. print.out()
D. System.out.println()
Ans: D
Difficult Level:
10.Which of the following is true about Java?
A. Java is interpreted only
B. Java is compiled only
C. Java is both compiled and interpreted
D. Java is neither
Ans: C
11.Which statement is true about Java bytecode?
A. It's generated by JVM
B. It runs directly on the hardware
C. It's an intermediate code executed by JVM
D. It is written manually
Ans: C
12.Which of the following keywords is used for inheritance in Java?
A. extends
B. implements
C. inherit
D. derives
Ans: A

UNIT-4:
Class and Object Properties-Java basics: Advantages, byte-code, JVM, Datatypes, access
specifiers, operators, control statements, loops, Arrays, classes, objects, constructors,
Garbage collection, method overloading, this keyword, static variables/methods, nested and
inner classes, String handling: String and String Buffer class methods, Command-line
arguments.
Easy Level:
1. Which is a correct array declaration in Java?
A. int arr[] = new int[5];
B. int arr = [5];
C. int arr = new array(5);
D. int[] = arr[5];
Ans: A
2. Which access modifier is the most restrictive?
A. public
B. private
C. protected
D. default
Ans: B
3. Which operator is used for comparison in Java?
A. =
B. ==
C. :=
D. =>
Ans: B
4. Which loop always executes at least once?
A. for
B. while
C. do-while
D. if
Ans: C
5. Which keyword is used to define a method that belongs to the class, not instances?
A. static
B. final
C. this
D. new
Ans: A
6. The String class in Java is:
A. Mutable
B. Immutable
C. Abstract
D. Static
Ans: B
7. Which class is used for mutable strings?
A. String
B. StringBuffer
C. CharSequence
D. CharArray
Ans: B
8. What is JVM short for?
A. Java Very Machine
B. Java Virtual Machine
C. Java Verified Method
D. Java Variable Manager
Ans: B
9. Which of the following is not a Java data type?
A. int
B. boolean
C. real
D. char
Ans: C
10.Which keyword refers to the current object?
A. super
B. static
C. final
D. this
Ans: D
Moderate Level:
11.What will happen if we try to use an uninitialized local variable?
A. Compiles and prints 0
B. Throws a runtime error
C. Compilation error
D. Compiles but gives garbage value
Ans: C
12.Which access modifier allows access within the same package only?
A. public
B. protected
C. private
D. default (no modifier)
Ans: D
13.Which loop is best suited when the number of iterations is known?
A. while
B. do-while
C. for
D. enhanced-for
Ans: C
14.Which of the following is not a primitive datatype in Java?
A. int
B. float
C. string
D. boolean
Ans: C
15.StringBuffer is used for:
A. Immutable string manipulation
B. Mutable string operations
C. Converting to float
D. Handling arrays
Ans: B
16.Which of these is not a valid constructor rule in Java?
A. Same name as class
B. Can have return type
C. Can be overloaded
D. Can be private
Ans: B
17.Nested class defined inside a method is called:
A. Anonymous class
B. Static nested class
C. Local inner class
D. Top-level class
Ans: C
Difficult Level:
18.Which of the following can be used to define a constant in Java?
A. static
B. final
C. const
D. define
Ans: B
19.Which method is automatically called during garbage collection?
A. start()
B. remove()
C. finalize()
D. delete()
Ans: C
20.What does the this keyword refer to?
A. Current package
B. Parent class
C. Current object
D. JVM
Ans: C

UNIT-5:
Reusability: Super class and sub classes, multilevel hierarchy, Constructor calling in
inheritance, Use of super and final keywords, Dynamic method dispatch, Abstract classes
and interfaces, Creating and importing packages.
Easy Level:
1. Which of these allows a class to inherit another?
A. extend
B. implements
C. extends
D. super
Ans: C
2. What is the base class of all Java classes?
A. Object
B. Main
C. System
D. Parent
Ans: A
3. Can interfaces contain method definitions?
A. Yes
B. No
C. Only final methods
D. Only constructors
Ans: B
4. Which of the following can extend a class?
A. Another class
B. An interface
C. A method
D. A package
Ans: A
5. Which keyword is used to prevent a method from being overridden?
A. static
B. protected
C. private
D. final
Ans: D
6. Which keyword is used to inherit from an interface?
A. extends
B. inherits
C. implements
D. interface
Ans: C
7. Which method is called when an object is created?
A. main()
B. create()
C. constructor
D. init()
Ans: C
8. Which package is imported by default in Java programs?
A. java.io
B. java.lang
C. java.util
D. java.package
Ans: B
9. Which keyword is used to create packages?
A. package
B. import
C. class
D. module
Ans: A
10.Which file extension is used for Java source code?
A. .jav
B. .jvm
C. .java
D. .jclass
Ans: C
Moderate Level:
11.Which constructor is called first in multilevel inheritance?
A. Most derived
B. Subclass
C. Superclass
D. Default class
Ans: C
12.Which keyword prevents method overriding?
A. static
B. private
C. final
D. const
Ans: C
13.What will happen if an abstract method is not implemented?
A. Runtime error
B. Compile-time error
C. Method gets deleted
D. Nothing happens
Ans: B
14.Can abstract classes have constructors?
A. No
B. Only static constructors
C. Yes
D. Only if it has abstract methods
Ans: C
15.Which of these can be used to group classes logically?
A. Interface
B. Abstract class
C. Package
D. Object
Ans: C
16.Which access level must a package-private class have?
A. public
B. private
C. default (no modifier)
D. protected
Ans: C
17.What happens if we don’t import a package in Java?
A. Program runs
B. Program compiles but doesn't run
C. Compilation error
D. JVM will crash
Ans: C
Difficult Level:
18.What is the purpose of the super keyword?
A. Access static methods
B. Access superclass constructor/method
C. Call main()
D. Import packages
Ans: B
19.Which of these allows implementation of multiple inheritance?
A. Class
B. Interface
C. Abstract class
D. Final class
Ans: B
20.Which of the following restricts inheritance in Java?
A. abstract
B. interface
C. super
D. final
Ans: D

UNIT-6:
Exception Handling and Multithreading: Basics of exception handling: try, catch, throw,
throws, and finally, User-defined exception classes, Basics of multithreading: thread lifecycle,
thread priorities, synchronization, deadlocks, inter-thread communication.
Easy Level:
1. Which block is used to catch exceptions?
A. try
B. throw
C. catch
D. throws
Ans: C
2. Which exception is thrown when dividing by 0?
A. NullPointerException
B. ArithmeticException
C. IOException
D. ZeroDivisionError
Ans: B
3. Which keyword is used to define an exception in method signature?
A. throw
B. catch
C. finally
D. throws
Ans: D
4. Which class is the parent of all exceptions?
A. Throwable
B. Error
C. Exception
D. RuntimeException
Ans: A
5. Which of the following is used to stop a thread?
A. end()
B. terminate()
C. stop()
D. Thread ends on its own
Ans: D
6. Which method is used to run the thread logic?
A. start()
B. init()
C. execute()
D. run()
Ans: D
7. A thread in Java can be created by:
A. Extending Thread class
B. Implementing Runnable interface
C. Both A and B
D. Using static methods
Ans: C
8. Which of these is not part of thread lifecycle?
A. Running
B. Paused
C. New
D. Terminated
Ans: B
9. Which class provides sleep method for threads?
A. Thread
B. Runnable
C. System
D. Timer
Ans: A
10.Which of the following is true about synchronized blocks?
A. Allows multiple threads to access
B. Prevents simultaneous access
C. Makes thread wait forever
D. Crashes JVM
Ans: B
11.Which keyword handles multiple exceptions?
A. multi
B. try-catch
C. catch
D. catch with pipe symbol (|)
Ans: D
12.Which method is used for inter-thread communication?
A. wait()
B. talk()
C. echo()
D. listen()
Ans: A
13.Deadlock is a situation when:
A. Threads run in parallel
B. Threads access same data safely
C. Threads wait on each other forever
D. Threads stop due to exception
Ans: C
14.Which method wakes up a thread from wait()?
A. notify()
B. start()
C. awake()
D. resume()
Ans: A
15.Which class must be extended to create a thread?
A. Runnable
B. Process
C. Thread
D. Main
Ans: C
Moderate Level:
16.Which block is always executed whether exception is handled or not?
A. try
B. catch
C. throw
D. finally
Ans: D
17.User-defined exceptions should inherit from:
A. Throwable
B. Error
C. Runtime
D. Exception
Ans: D
18.Which method is used to wait for a thread to die?
A. wait()
B. kill()
C. join()
D. stop()
Ans: C
19.Which exception occurs when a thread is waiting indefinitely for a lock?
A. TimeoutException
B. Deadlock
C. NullPointerException
D. StackOverflowError
Ans: B
20.Which method allows one thread to communicate with another?
A. notify()
B. talk()
C. run()
D. execute()
Ans: A
21.Thread priority ranges from:
A. 0 to 5
B. 1 to 10
C. 0 to 10
D. 1 to 5
Ans: B
Difficult Level:
22.Which keyword is used to manually throw an exception?
A. throw
B. throws
C. try
D. finally
Ans: A
23.Which method starts a thread in Java?
A. run()
B. start()
C. init()
D. execute()
Ans: B
24.What is the purpose of the synchronized keyword?
A. To enable multithreading
B. To stop all threads
C. To avoid race condition
D. To compile code
Ans: C

You might also like