1.
What of the following is the default value of an instance variable?
Correct Answer
C. Depends upon the type of variable
Explanation
The default value of an instance variable depends upon the type of variable. In Java, the default value for numeric types (such as int, float, double) is 0, for boolean it is false, and for reference types (such as String) it is null. Therefore, the correct answer is "Depends upon the type of variable."
2.
What is the size of the float variable?
Correct Answer
C. 32 bit
Explanation
The size of the float variable is 32 bits.
3.
What is the default value of the String variable?
Correct Answer
C. Null
Explanation
The default value of a String variable is null. This means that if a String variable is not assigned a value, it will automatically have a null value.
4.
Which of the following is true about public access modifier?
Correct Answer
A. Variables, methods and constructors which are declared public can be accessed by any class.
Explanation
The public access modifier allows variables, methods, and constructors to be accessed by any class, regardless of whether they are in the same package or not. This means that any class, regardless of its location, can access and use the public members of a class. Therefore, the correct answer is that variables, methods, and constructors declared as public can be accessed by any class.
5.
What is Abstraction?
Correct Answer
C. It refers to the ability to make a class abstract in OOP.
Explanation
Abstraction in object-oriented programming (OOP) refers to the ability to make a class abstract. An abstract class is a class that cannot be instantiated and is meant to be subclassed. It provides a common interface for all the subclasses, but each subclass can have its own implementation. This allows for the concept of abstraction, where the essential details and behaviors of an object are captured in an abstract class, while the specific implementation details are left to the subclasses.
6.
What is an applet?
Correct Answer
A. An applet is a Java program that runs in a Web browser.
Explanation
An applet is a Java program that runs in a Web browser. This means that it is a small application written in the Java programming language that can be embedded within a web page and executed within a web browser. Applets are often used to provide interactive and dynamic content on websites, such as animations, games, or interactive forms. They have access to the browser's capabilities and can interact with the web page's HTML content. Applets are different from standalone Java programs, which are executed outside of a web browser.
7.
What is NullPointerException?
Correct Answer
A. A NullPointerException is thrown when calling the instance method of a null object or modifying/accessing field of a null object.
Explanation
A NullPointerException is thrown when calling the instance method of a null object or modifying/accessing field of a null object. This means that if we try to perform any action on an object that is null (has no value assigned to it), such as calling a method or accessing a field, a NullPointerException will be thrown. This is because null objects do not have any methods or fields associated with them, so attempting to access them will result in an error.
8.
What happens when the thread's yield() method is called?
Correct Answer
A. Thread returns to the ready state.
Explanation
When the thread's yield() method is called, it temporarily pauses its execution and allows other threads of the same priority to run. It does not go back to the waiting state because it is not waiting for any specific condition or resource. Instead, it goes back to the ready state, where it is eligible to run again when the scheduler chooses it. This allows for fair scheduling and prevents a single thread from monopolizing the CPU.
9.
Is it necessary that each try block must be followed by a final block?
Correct Answer
B. False
Explanation
It is not necessary for each try block to be followed by a final block. A final block, also known as a finally block, is used to define a section of code that will always be executed, regardless of whether an exception is thrown or not. While it is a good practice to include a final block to handle any necessary cleanup operations, it is not mandatory. In some cases, the try block may be followed by catch blocks to handle specific exceptions, without the need for a final block.
10.
Which of the following is a marker interface?
Correct Answer
A. Serializable
Explanation
A marker interface is an interface that does not contain any methods but is used to mark or tag a class. In this case, the correct answer is "serializable" because it is a marker interface in Java that indicates that a class can be serialized, meaning its objects can be converted into a byte stream for storage or transmission.