Search Header Logo

Java Test 1

Authored by Vikas Bandaru

Computers

10th Grade

Used 5+ times

Java Test 1
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

15 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the correct way to declare an instance variable in Java?

public static int myVariable;
static public int myVariable;
int myVariable;
protected int myVariable;

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the purpose of a constructor in Java?

To define a variable
To create a new class
To call a method
To initialize instance variables

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the difference between a class and an object in Java?

A class is a blueprint for an object, while an object is an instance of a class.
A class is a data type, while an object is a variable.
A class contains variables and methods, while an object contains only variables.
A class can have multiple instances, while an object is a single instance of a class.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the correct way to define a setter method in Java?

public void setMyVariable();
public setMyVariable(int value);
public void setMyVariable(int value) { myVariable = value; }
All of the above

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is a correct syntax for a single-line comment in Java?

/*This is a comment*/
This is a comment//
// This is a comment
# This is a comment

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the purpose of a getter method in Java?

To get the value of a variable
To set the value of a variable
To create a new object
All of the above

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the correct way to declare a class in Java?

public MyClass { // code block }

class public MyClass() { // code block }

public class MyClass { // code block }

None of the above

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

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?