Intro to Java
Programming

5 questions · Test your fundamentals

Q 01 / 05 Basics

Which keyword is used to print output to the console in Java?

System.out.println() is Java's standard way to print to the console. System is a class, out is a PrintStream field, and println prints the text followed by a newline.
Q 02 / 05 Data Types

What is the output of the following code?

int x = 5; int y = 2; System.out.println(x / y);
2 — Java performs integer division when both operands are int. The decimal part is truncated, so 5 / 2 = 2, not 2.5. To get 2.5, cast one operand to double: (double) x / y.
Q 03 / 05 OOP

In Java, which access modifier makes a class member accessible only within the same class?

private restricts access to within the declaring class only. public = everywhere; protected = same package + subclasses; default (no modifier) = same package only.
Q 04 / 05 Control Flow

How many times will the following loop print "Hello"?

for (int i = 0; i < 5; i++) { System.out.println("Hello"); }
5 times. The loop starts at i = 0 and runs while i < 5, so it executes for i = 0, 1, 2, 3, 4 — exactly 5 iterations.
Q 05 / 05 Strings

Which method is used to find the number of characters in a Java String?

length() returns the number of characters in a String. For example, "Java".length() returns 4. Note: arrays use .length (property), but Strings use .length() (method).

Quiz Complete!

0%

You answered 0 out of 5 correctly.

0
Correct
0
Wrong