menu

Java Basics

Java Basics - Important Points


26. Which of the following is NOT a loop in Java?

A. while

B. for

C. do-while

D. if

Discuss Work Space

Answer: option d

Explanation:

If is a conditional statement, not a loop.

27.

What is the output of the following code?

public class Test {
public static void main(String args[]) {
int x = 10;
if(x > 5 && x < 15) {
System.out.println("x is between 5 and 15");
} else {
System.out.println("x is not between 5 and 15");
  }
 }
}

A. x is between 5 and 15

B. x is not between 5 and 15

C. 5 and 15

D. No output

Discuss Work Space

Answer: option a

Explanation:

The condition x > 5 && x < 15 is true, so the output is "x is between 5 and 15".


28. Which of the following is a valid way to declare a variable in Java?

A. int x = 5;

B. int 5 = x;

C. x = 5;

D. int x;

Discuss Work Space

Answer: option a

Explanation:

Option A shows the correct syntax for declaring and initializing a variable in Java.

29.

What is the output of the following program?

public class Test {
public static void main(String args[]) {
int x = 10;
int y = x++;
System.out.println(y);
  }
}

A. 10

B. 11

C. 9

D. None of the above

Discuss Work Space

Answer: option a

Explanation:

The post-increment operator (++) increases the value of x after it has been assigned to y. In this case, y is assigned the value of 10 before x is incremented to 11.


30. Which of the following is NOT a valid way to create an object in Java?

A. MyClass object = new MyClass();

B. MyClass object = MyClass();

C. MyClass object;

D. MyClass object = null;

Discuss Work Space

Answer: option b

Explanation:

Option B is not a valid way to create an object in JavThe correct syntax for creating an object is to use the "new" keyword.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now