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
View Answer Discuss Work SpaceAnswer: option d
Explanation:
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
View Answer Discuss Work SpaceAnswer: 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;
View Answer Discuss Work SpaceAnswer: option a
Explanation:
29. | What is the output of the following program? public class Test { |
---|
A. 10
B. 11
C. 9
D. None of the above
View Answer Discuss Work SpaceAnswer: 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;
View Answer Discuss Work SpaceAnswer: option b
Explanation: