Java Exercises

Fill in the blanks to test your knowledge.

1

Declare an integer variable called age

age = 25;
2

Print a message to the console

System.out.("Hello Java");
3

Define a public class named Animal

Animal {
// class body
}
4

Create a method that returns a String

public getName() {
return name;
}
5

Write a for loop from 0 to 4

for ( i = 0; i < 5; i++) {
System.out.println(i);
}
6

Make Dog extend Animal using inheritance

public class Dog Animal {
// Dog body
}
7

Declare a String array of size 3

String[] names = String[3];
8

Use the boolean type for a flag variable

isActive = true;