Search Header Logo

Intro: Variable Scope

Authored by Wayground CTE

Information technology (IT)

9th Grade

Blooms Level: Remember covered

Intro: Variable Scope
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

5 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Where is a local variable declared?

At the top of a Java source file

Outside every method in the class body

Inside a method, constructor, or block

Directly beneath the class declaration

Answer explanation

A local variable is declared inside a method, constructor, or block and exists only within that scope. Variables declared outside all methods are instance or static variables.

Tags

Blooms Level: Remember

2.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Which keyword makes a variable a class (static) variable?

Static

Final

Public

Private

Answer explanation

The static keyword makes a variable belong to the class itself rather than to any individual object. public and private control access, not scope type.

Tags

Blooms Level: Remember

3.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

How does an instance variable differ from a local variable?

Declared inside a method body

Requires the static keyword

Belongs to an object; lives for the object's lifetime

Accessible within one block only

Answer explanation

An instance variable is declared in the class body outside any method, so each object gets its own copy. A local variable exists only inside the method or block where it is declared.

Tags

Blooms Level: Understand

4.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

A variable declared inside an if block is accessible

Only within that if block

Throughout the entire method

Anywhere in the Java file

From any method in the class

Answer explanation

A variable declared inside a block, such as an if statement, has block scope and cannot be used outside that block.

Tags

Blooms Level: Remember

5.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Where must an instance variable be declared in a Java class?

Inside a constructor block only

Inside a loop within a method body

Inside the main method body

In the class body, outside any method

Answer explanation

Instance variables are declared directly in the class body, outside any method or constructor, so every object gets its own copy. Variables inside constructors or methods are local variables.

Tags

Blooms Level: Remember

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Microsoft

Continue with Microsoft

or continue with

Facebook

Facebook

Apple

Apple

Others

Others

Already have an account?