Syntax
Class Methods
Objects and Classes
Conditional Statements and Boolean Operators
Defining Classes
100

What is the correct way to declare an integer variable named count?

private int count;

100

How can you concatenate two strings firstName and lastName in Java?

String fullName = firstName + lastName;

100

What is an object in programming?

An object is an instance of a class that encapsulates data and behavior.

100

What is the syntax for an if statement in Java?

  if (condition) {      // code to execute  }

100

What is the basic syntax to define a new class namedPerson?

 public class Person {      // class body  }

200

How do you assign the value 5 to a double variable named temperature?

double temperature = 5.0;

200

What method would you use to find the length of a string?

stringVariable.length();


200

Define a constructor and its purpose.

A constructor is a special method that initializes an object when it is created.

200

How can you check if a boolean variableisReadyis false?

if (!isReady) { // code }

200

How do you define a method that takes an int parameter and returns a boolean?

 public boolean methodName(int parameter) {      // implementation  }

300

What is the difference between integer and floating-point arithmetic?

Integer arithmetic deals with whole numbers, while floating-point arithmetic can represent decimal values.

300

Describe how to generate a random integer between 1 and 10 with the Math class?

int randomNum = (int)(Math.random() * 10) + 1;

300

How do you access a global variable from inside a class?

this.instanceVariableName

300

What are the three main Boolean operators in Java?

AND (&&), OR (||), NOT (!)

300

Describe the role of instance variables in a class.

Instance variables hold the state of an object and are specific to each instance of the class.

400

In Java, what is the keyword used to define a constant?

final

400

What is the output of the following code: System.out.println(Math.abs(-5));?

5

400

What is the difference between public and private instance variables?

Public variables can be accessed from outside the class, while private variables can only be accessed within the class.

400

What is the result of the following

int x = 5, y = 6;

int result = !(x<5 || y>5);

result = false

400

What is an API documentation and how is it useful?

API documentation provides detailed information about classes, methods, and functionalities available in a programming language, helping developers to understand and use them effectively. 

500

Explain the significance of variable scope in programming.

Variable scope determines where a variable can be accessed and is typically defined by where it is declared (e.g., local vs. instance scope).

500

Explain how you would round a double to the nearest whole number.

Math.round(doubleValue);

500

Explain how you would define a class named 

Car with a method startEngine()

  public class Car {      

public void startEngine() {         

 // implementation     

 }

  }

500

What is the result of the expression true && (true || (false && true))?

true

500

Define how you would perform unit testing using a simplemain()method.

By creating an instance of the class and calling the methods to verify expected outcomes, e.g.,public static void main(String[] args) { /* testing code */ }

M
e
n
u