menu

Java Basic Programs for Beginners

Java Basic Programs for Beginners - Important Points


16. Which of the following is a valid way to create a new object in Java?

A. Object obj = new Object();

B. Object obj = Object();

C. Object obj = new Object;

D. Object obj = Object;

Discuss Work Space

Answer: option a

Explanation:

Option A is a valid way to create a new object in Java.

17.

What is the output of the following program?

public class Main {
public static void main(String[] args) {
int x = 5;
int y = 2;
System.out.println(x >= y);
 }
}

A. 1

B. 0

C. Compile error

D. Runtime error

Discuss Work Space

Answer: option a

Explanation:

The expression x >= y compares the values of x and y for greater than or equal to, which is true in this case.

18. Which of the following is not a valid access modifier in Java?

A. private

B. public

C. protected

D. global

Discuss Work Space

Answer: option d

Explanation:

global is not a valid access modifier in Java.

19.

What is the output of the following program?

public class Main {
public static void main(String[] args) {
int x = 5;
int y = 2;
System.out.println(x != y);
 }
}

A. 1

B. 0

C. Compile error

D. Runtime error

Discuss Work Space

Answer: option a

Explanation:

The expression x != y compares the values of x and y for not equal to, which is true in this case.

20. Which of the following is not a primitive data type in Java?

A. int

B. float

C. string

D. char

Discuss Work Space

Answer: option c

Explanation:

string is not a primitive data type in JavIt is a class in the Java standard library. The correct spelling for the string class is String with a capital S.


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