0

Basic Java Programming Quiz 2

Description: Basic Java Programming Quiz 2
Number of Questions: 13
Created by:
Tags: java
Attempted 0/13 Correct 0 Score 0

Methods that are marked protected can be called in any subclass of that class.

  1. True

  2. False


Correct Option: A

An abstract class can have non-abstract methods.

  1. True

  2. False


Correct Option: A

Java keywords are written in lowercase as well as uppercase.

  1. True

  2. False


Correct Option: B

What is an instanceof

  1. A methods in object

  2. An operator and keyword


Correct Option: B

Primitive datatypes are allocated on a stack.

  1. True

  2. False


Correct Option: A

AI Explanation

To answer this question, we need to understand the concept of primitive data types and the stack.

Primitive data types, such as integers, floats, booleans, and characters, are basic data types provided by programming languages. They store simple values and have a fixed size.

The stack is a region of memory used for local variables and function calls. It follows a LIFO (Last-In, First-Out) principle, where the last item pushed onto the stack is the first one to be popped off.

Now, let's go through the options:

Option A) True - This option is correct. Primitive data types are typically allocated on the stack. When a primitive variable is declared and assigned a value, it is stored on the stack. The memory allocated for the variable is freed when it goes out of scope or when the function it is defined in returns.

Option B) False - This option is incorrect. Primitive data types are not allocated on the heap, but rather on the stack.

The correct answer is Option A) True. Primitive data types are allocated on the stack.

Can you compare a boolean to an integer?

  1. Yes

  2. No


Correct Option: B

Integer a = new Integer(2); Integer b = new Integer(2); What happens when you do if (a==b)?

  1. Compiler error

  2. Runtime Exception

  3. True

  4. False


Correct Option: D

The methods wait(), notify() and notifyAll() in Object need to be called from synchronized pieces of code.

  1. True

  2. False


Correct Option: A

Synchronized is a keyword to tell a Thread to grab an Object lock before continuing execution.

  1. True

  2. False


Correct Option: A

The default statement of a switch is always executed.

  1. True

  2. False


Correct Option: B

How can you prevent a member variable from becoming serialized?

  1. By marking it private

  2. By marking it volatile

  3. By marking it transient

  4. You can not.


Correct Option: C
- Hide questions