Author name: admin

Which of the following is not a valid access modifier in Java?

Java MCQ: Which of the following is not a valid access modifier in Java? a) private b) protected c) public d) internal Answer: d) internal Explanation: In Java, the valid access modifiers are private, protected, and public. These modifiers control the visibility of classes, methods, and variables. private makes a member accessible only within the […]

Which of the following is not a valid access modifier in Java? Read More »

Which of the following is a characteristic of the ‘transient’ keyword in Java?

Java MCQ: Which of the following is a characteristic of the ‘transient’ keyword in Java? a) It prevents serialization of the variable b) It ensures that the variable is serialized c) It allows the variable to be accessed from any thread d) It makes the variable immutable Answer: a) It prevents serialization of the variable

Which of the following is a characteristic of the ‘transient’ keyword in Java? Read More »

Which of the following statements is true about the ‘abstract’ keyword in Java?

Java MCQ: Which of the following statements is true about the ‘abstract’ keyword in Java? a) An abstract class cannot be instantiated b) Abstract methods do not have a body c) A class must be declared abstract if it contains abstract methods d) All of the above Answer: d) All of the above Explanation: The

Which of the following statements is true about the ‘abstract’ keyword in Java? Read More »

Which of the following statements about interfaces in Java is true?

Java MCQ: Which of the following statements about interfaces in Java is true? a) An interface can have instance variables b) An interface can extend multiple interfaces c) An interface can implement another interface d) An interface can have a constructor Answer: b) An interface can extend multiple interfaces Explanation: In Java, an interface can

Which of the following statements about interfaces in Java is true? Read More »

Which of the following best describes method overloading in Java?

Java MCQ: Which of the following best describes method overloading in Java? a) Method overloading occurs when two methods in the same class have the same name but different parameter lists b) Method overloading is the process of overriding a method in a subclass c) Method overloading refers to the runtime resolution of method calls

Which of the following best describes method overloading in Java? Read More »

Which of the following is not a method in the ‘String’ class?

Java MCQ: Which of the following is not a method in the ‘String’ class? a) length() b) substring() c) equalsIgnoreCase() d) size() Answer: d) size() Explanation: The Java String class provides a variety of methods for manipulating and inspecting strings. Common methods include length() for getting the length of the string, substring() for extracting a

Which of the following is not a method in the ‘String’ class? Read More »

Which of the following is not a valid method for converting a string to an integer in Java?

Java MCQ: Which of the following is not a valid method for converting a string to an integer in Java? a) Integer.parseInt() b) Integer.valueOf() c) String.toInt() d) None of the above Answer: c) String.toInt() Explanation: In Java, there are several ways to convert a string to an integer. The Integer.parseInt() method is commonly used to

Which of the following is not a valid method for converting a string to an integer in Java? Read More »

Which of the following is not a feature of Java?

Java MCQ: Which of the following is not a feature of Java? a) Dynamic b) Platform-independent c) Machine-dependent d) Multithreaded Answer: c) Machine-dependent Explanation: Java is designed to be platform-independent, meaning that Java programs can run on any device or operating system that has the Java Virtual Machine (JVM) installed. This “write once, run anywhere”

Which of the following is not a feature of Java? Read More »

Which of the following is used to compare the contents of two objects in Java?

Java MCQ: Which of the following is used to compare the contents of two objects in Java? a) == operator b) equals() method c) compareTo() method d) hashCode() method Answer: b) equals() method Explanation: In Java, the equals() method is used to compare the contents of two objects. Unlike the == operator, which compares the

Which of the following is used to compare the contents of two objects in Java? Read More »

Which of the following is true about the ‘abstract’ keyword in Java?

Java MCQ: Which of the following is true about the ‘abstract’ keyword in Java? a) Abstract classes cannot be instantiated b) Abstract methods do not have a body c) A class must be declared abstract if it contains abstract methods d) All of the above Answer: d) All of the above Explanation: The abstract keyword

Which of the following is true about the ‘abstract’ keyword in Java? Read More »

Which of the following interfaces is used to handle events in Java?

Java MCQ: Which of the following interfaces is used to handle events in Java? a) Runnable b) Serializable c) EventListener d) Cloneable Answer: c) EventListener Explanation: The EventListener interface in Java is used to handle events. It is a marker interface that all event listener interfaces must extend. Event listeners are objects that are notified

Which of the following interfaces is used to handle events in Java? Read More »

Which of the following is not a type of inheritance in Java?

Java MCQ: 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) Multiple inheritance through classes Explanation: In Java, multiple inheritance through classes is not supported. This means a class cannot inherit from more than one class.

Which of the following is not a type of inheritance in Java? Read More »

Which of the following is true about Java’s ‘String’ class?

Java MCQ: Which of the following is true about Java’s ‘String’ class? a) Strings are immutable b) Strings can be changed after they are created c) Strings are a primitive data type d) Strings are thread-unsafe by default Answer: a) Strings are immutable Explanation: In Java, the String class represents a sequence of characters. One

Which of the following is true about Java’s ‘String’ class? Read More »

Which of the following statements is true about the ‘static’ keyword in Java?

Java MCQ: Which of the following statements is true about the ‘static’ keyword in Java? a) Static methods can access instance variables directly b) Static methods belong to the class, not instances c) Static methods can override instance methods d) Static methods can be abstract Answer: b) Static methods belong to the class, not instances

Which of the following statements is true about the ‘static’ keyword in Java? Read More »

Which access modifier is used to allow access to members of a class within the same package but not from outside?

Java MCQ: Which access modifier is used to allow access to members of a class within the same package but not from outside? a) private b) protected c) public d) default Answer: d) default Explanation: In Java, when no access modifier is specified for a class member, the default access level is package-private, also known

Which access modifier is used to allow access to members of a class within the same package but not from outside? Read More »

Scroll to Top