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

Basic Level MCQ Oops

The document is a multiple-choice question test focused on basic Object-Oriented Programming (OOP) concepts in Java. It covers topics such as the main method, variable scope, data types, inheritance, polymorphism, abstraction, and encapsulation. Each question provides options to test the understanding of Java programming fundamentals.

Uploaded by

HEMALAKSHMI D
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 views15 pages

Basic Level MCQ Oops

The document is a multiple-choice question test focused on basic Object-Oriented Programming (OOP) concepts in Java. It covers topics such as the main method, variable scope, data types, inheritance, polymorphism, abstraction, and encapsulation. Each question provides options to test the understanding of Java programming fundamentals.

Uploaded by

HEMALAKSHMI D
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

Basic Level -OOPS MCQ TEST-1

Question 1: What is the signature of the main method in Java?

a) public static void main(String[] args)

b) public static int main(String args)

c) public void main(String[] args)

d) static void main(String[] args)

Question 2: Which keyword is used to indicate the entry point of a Java program?

a) start

b) run

c) main

d) begin

Question 3: In Java, can the main method be defined as non-static?

a) Yes

b) No

Question 4: What is the purpose of the String[] args parameter in the main method?

a) It is used to pass command-line arguments to the program.

b) It is the return type of the main method.

c) It specifies the number of arguments the main method can accept.

d) It is used to specify the access modifier of the main method.

Question 5: What happens if the main method is not declared as public static?

a) The program will not compile.

b) The program will run but will throw a runtime exception.

c) The program will run without any issues.

d) The main method must always be public static.


Question 6: How do you run a Java program from the command line if the main method is in a class
named MyClass?

a) java -class MyClass

b) java MyClass

c) java -main MyClass

d) java -run MyClass

Question 7: What is the return type of the main method?

a) void

b) int

c) String

d) boolean

Question 8: How can you pass command-line arguments to a Java program?

a) By using the java command followed by arguments

. b) By defining a main method that accepts arguments

. c) By using the args keyword in the program.

d) By specifying arguments in the program's comments.

Question 9: Can a Java program have multiple main methods?

a) Yes, but only one of them can be executed.

b) No, a Java program can have only one main method.

c) Yes, all main methods are executed in parallel.

d) Yes, and all of them are executed sequentially.

Question 10: Which of the following is the correct way to declare the main method with arguments in
Java?

a) public static void main(String args[])

b) public static void main(String args...)

c) public void static main(String[] args)


d) public void main(args[])

Question 11: Which of the following is NOT a valid Java variable name?

a) myVariable

b) MyVariable

c) my-variable

d) _myVariable

Question 12: What is the scope of a local variable in Java?

a) It is accessible throughout the entire class.

b) It is accessible only within the method or block where it is declared.

c) It is accessible within any method of the same class.

d) It is accessible within any class in the same package.

Question 13: Which of the following data types is used to store a single character in Java?

a) int

b) char

c) boolean

d) String

Question 14: What is the default value of an instance variable (non-static) in Java if it is not explicitly
initialized?

a) 0

b) null

c) false

d) There is no default value; it must be initialized before use.

Question 15: Which access modifier allows a variable to be accessed from any class in the same
package?
a) public

b) private

c) protected

d) Default (no modifier)

Question 16: What is the purpose of the final keyword when applied to a variable in Java?

a) It indicates that the variable cannot be modified after initialization.

b) It makes the variable accessible from other classes.

c) It specifies the initial value of the variable.

d) It allows the variable to be overridden in subclasses.

Question 17: Which of the following is NOT a valid way to declare and initialize a constant variable in
Java?

a) final int PI = 3.14159;

b) final double PI = 3.14159;

c) const PI = 3.14159;

d) static final float PI = 3.14159;

Question 18: What is the range of values that can be stored in a byte variable in Java?

a) -128 to 127

b) -32768 to 32767

c) 0 to 255

d) -2^31 to 2^31 - 1

Question 1 9: Which keyword is used to declare a constant in Java?

a) constant

b) const

c) final

d) static

Question 20: What is the purpose of the static keyword when applied to a variable in Java?
a) It indicates that the variable is a class variable (shared among all instances of the class).

b) It makes the variable accessible only within the same method.

c) It allows the variable to be modified after initialization.

d) It specifies the data type of the variable.

Question 21: Which Java statement is used to control the flow of a program based on a condition?

a) switch

b) for

c) if

d) do-while

Question 22: In Java, what is the purpose of the else statement in an if-else construct?

a) To define the condition to be checked.

b) To specify the action to be executed if the if condition is true.

c) To specify the action to be executed if the if condition is false.

d) To exit the loop.

Question 23: Which of the following loop constructs is designed for situations where the loop body
should always execute at least once?

a) while

b) for

c) do-while

d) if

Question 24: In a switch statement in Java, what is the purpose of the break statement?

a) To execute the code block for the current case and continue to the next case.

b) To exit the switch statement and continue with the code after the switch.

c) To indicate the default case.

d) To define a new case.

Question 25: What is the role of the break statement in a loop in Java?
a) It continues to the next iteration of the loop.

b) It exits the loop and continues with the code after the loop.

c) It restarts the loop from the beginning.

d) It defines a new loop iteration.

Question 26: What is the output of the following code snippet?

int x = 5; if (x > 3)

[Link]("x is greater than 3");

} else

{ [Link]("x is not greater than 3"); }

a) "x is greater than 3"

b) "x is not greater than 3"

c) Both statements are printed.

d) None of the above.

Question 27: Which loop construct is best suited for situations where the number of iterations is known
in advance?

a) while

b) for

c) do-while

d) if

Question 28: In a for loop in Java, where is the initialization statement typically placed?

a) At the beginning of the loop body.

b) After the loop body.

c) Before the condition.

d) Inside the loop body.

Question 29: What is the output of the following code snippet?


int i = 0; while (i < 5)

{ [Link](i + " "); i++;

a) 0 1 2 3 4

b) 1 2 3 4 5

c) 0 1 2 3 4 5

d) The code contains an error.

Question 30: In Java, what does the continue statement do in a loop?

a) Exits the loop completely.

b) Skips the current iteration and continues with the next iteration of the loop.

c) Breaks out of the loop.

d) Restarts the loop from the beginning.

Question 31: In Java, which keyword is used to indicate inheritance between classes?

a) inherits

b) inherits from

c) extends

d) implements

Question 32: Which type of inheritance allows a class to inherit from multiple classes in Java?

a) Single inheritance

b) Multiple inheritance

c) Multilevel inheritance

d) Hierarchical inheritance

Question 33: In Java, which keyword is used to prevent a class from being inherited by other classes?

a) sealed

b) final
c) static

d) private

Question 34: What is the primary purpose of the super keyword in Java?

a) To call the superclass constructor.

b) To access static members of the superclass.

c) To create an instance of the superclass.

d) To access the current class's instance variables.

Question 35: In Java, which class serves as the ultimate superclass for all classes, directly or indirectly?

a) [Link]

b) [Link]

c) [Link]

d) [Link]

Question 36: Which of the following statements is true regarding method overriding in Java?

a) A subclass can override a private method from its superclass.

b) A subclass can override a static method from its superclass.

c) A subclass can override a final method from its superclass.

d) A subclass can override a constructor from its superclass.

Question 37: In Java, what is the concept of method hiding?

a) It is an error that occurs when a method is defined with the same name in the subclass.

b) It refers to the ability of a subclass to hide methods of its superclass.

c) It allows a method to be hidden by changing its name in the subclass.

d) It refers to the encapsulation of methods in a class.

Question 38: Which access modifier allows a subclass to access members of its superclass in Java?

a) private
b) protected

c) public

d) static

Question 39: In Java, which keyword is used to call a constructor of the superclass from a subclass
constructor?

a) superclass

b) extends

c) super

d) this

Question 40: What is the term for a class that cannot be instantiated and is used solely as a base for
other classes in Java?

a) Abstract class

b) Final class

c) Concrete class

d) Inherited class

Question 41: What is polymorphism in Java?

a) The ability to inherit multiple classes

b) The ability to define multiple constructors in a class

c) The ability of a class to have multiple methods with the same name but different parameters

d) The ability to create multiple objects of a class

Question 42: Which type of polymorphism is achieved through method overriding?

a) Compile-time polymorphism

b) Run-time polymorphism

c) Static polymorphism

d) Dynamic polymorphism

Question 43: In Java, what is method overloading?


a) Defining multiple methods with the same name and the same parameters in a class

b) Defining multiple methods with the same name but different parameters in a class

c) Defining a method inside another method

d) Defining a method to return different data types

Question 44: What is the return type considered when determining method overloading in Java?

a) It is not considered.

b) It must be the same for all overloaded methods.

c) It must be different for all overloaded methods.

d) It is optional and does not affect method overloading.

Question 45: Which keyword is used to indicate that a method is being overridden in a subclass?

a) overriding

b) extends

c) super

d) @Override

Question 46: In Java, which method is called when an object is created using the new keyword?

a) constructor

b) finalize

c) initialize

d) start

Question 47: What is the benefit of using polymorphism in Java?

a) It allows classes to have multiple constructors.

b) It enables dynamic method invocation at runtime.

c) It allows access to private methods in other classes.

d) It prevents method overriding.

Question 48: Which type of polymorphism is achieved through method overloading?


a) Compile-time polymorphism

b) Run-time polymorphism

c) Static polymorphism

d) Dynamic polymorphism

Question 49: In Java, can a subclass override a method with a lower access level than the superclass?

a) Yes, as long as the subclass is in the same package as the superclass.

b) Yes, as long as the subclass is in a different package from the superclass.

c) No, the access level must be the same or higher in the subclass.

d) No, method overriding is not allowed in Java.

Question 50: What is the term for a reference variable that can refer to objects of multiple classes?

a) Multiclass reference

b) Polymorphic reference

c) Variable reference

d) Class variable

Question 51: What is abstraction in Java?

a) The process of creating multiple objects from a class

b) The process of hiding the implementation details and showing only the necessary features of an
object

c) The process of defining multiple constructors in a class

d) The process of implementing all methods of an interface

Question 52: Which keyword is used to declare an abstract class in Java?

a) abstract

b) class

c) interface

d) extends

Question 53: Can an abstract class have concrete (non-abstract) methods?


a) Yes, it can have both abstract and concrete methods.

b) No, all methods in an abstract class must be abstract.

c) Yes, but only if the class is marked as final.

d) No, an abstract class can have only abstract methods.

Question 54: What is the purpose of an abstract method in an abstract class?

a) To provide a default implementation for the method.

b) To declare a method without providing its implementation.

c) To make the method accessible to any class.

d) To prevent the method from being overridden.

Question 55: In Java, can an abstract class be instantiated (i.e., an object of the abstract class be
created)?

a) Yes, an abstract class can be instantiated like any other class.

b) No, an abstract class cannot be instantiated; it can only be used as a base class for other classes.

c) Yes, but only if all its methods are concrete (non-abstract).

d) No, an abstract class can be instantiated, but it cannot be used as a base class.

Question 56: What is the purpose of the abstract keyword when applied to a method in Java?

a) It indicates that the method can be overridden.

b) It indicates that the method is private.

c) It indicates that the method has a default implementation.

d) It indicates that the method is abstract and must be overridden in a subclass.

Question 57: Which of the following is NOT a valid use of abstraction in Java?

a) Creating abstract classes to define a common interface for multiple subclasses

b) Implementing interfaces to provide a set of methods that must be defined by implementing classes

c) Using the final keyword to prevent a class from being subclassed

d) Declaring abstract methods to provide a blueprint for subclasses

Question 58: Can a concrete (non-abstract) class inherit from an abstract class in Java?
a) Yes, but the concrete class must implement all abstract methods of the abstract class.

b) No, a concrete class cannot inherit from an abstract class.

c) Yes, and it is not required to implement any abstract methods.

d) Yes, but the concrete class can choose which abstract methods to implement.

Question 59: In Java, what is the term for a class that inherits from an abstract class and provides
concrete implementations for all its abstract methods?

a) Concrete class

b) Subclass

c) Abstract class

d) Superclass

Question 60: What is the relationship between an interface and abstraction in Java?

a) An interface is a type of abstraction that defines a contract for methods.

b) An interface is an abstract class with no abstract methods.

c) An interface is a concrete class with all methods implemented.

d) An interface cannot be used in conjunction with abstraction.

Question 61: What is encapsulation in Java?

a) The process of hiding implementation details and showing only necessary features of an object.

b) The process of defining multiple constructors in a class.

c) The process of creating multiple objects from a class.

d) The process of defining multiple methods with the same name but different parameters in a class.

Question 62: Which access modifiers are used in Java to control access to class members (fields and
methods)?

a) public and private

b) protected and final

c) static and abstract

d) extends and implements


Question 63: In Java, which access modifier allows a class member to be accessed from anywhere, both
within and outside the class?

a) public

b) private

c) protected

d) default (no modifier)

Question 64: What is the purpose of using private access modifier for a class member in Java?

a) To allow access to the member only within the same class.

b) To allow access to the member from any class in the same package.

c) To make the member accessible from any class, even those outside the package.

d) To prevent access to the member from any class.

Question 65: Which of the following is true regarding encapsulation in Java?

a) Encapsulation allows unrestricted access to class members.

b) Encapsulation promotes data hiding and restricted access to class members.

c) Encapsulation is achieved by using the public access modifier for all members.

d) Encapsulation is not a concept in Java.

Question 66: In Java, what is the purpose of providing public getter and setter methods for private
fields? a) To make the fields directly accessible from any class.

b) To allow modification of the fields without restrictions.

c) To provide controlled access to the fields and enforce data validation.

d) To hide the fields completely from other classes.

Question 67: Which of the following is an advantage of encapsulation in Java?

a) It makes all class members accessible from any class.

b) It eliminates the need for getters and setters.

c) It allows unrestricted modification of class members.

d) It protects the integrity of data and allows controlled access.


Question 68: In Java, which keyword is used to declare a private class member?

a) private

b) public

c) protected

d) static

Question 69: Which of the following statements is true regarding encapsulation?

a) Encapsulation is only applicable to public class members.

b) Encapsulation does not allow any access to class members.

c) Encapsulation can be achieved by declaring all class members as static.

d) Encapsulation is a fundamental concept of object-oriented programming.

Question 70: In Java, can encapsulation be applied to fields without providing getter or setter methods?
a) Yes, as long as the fields are declared as public.

b) No, getter and setter methods are mandatory for encapsulation.

c) Yes, but the fields must be declared as final.

d) No, encapsulation requires both private fields and corresponding getter/setter methods.

You might also like