Skip to content
javabeginner

Java Basics Quiz

Syntax, types, classes, inheritance, and core Java concepts.

7 questions

By EZ4Code Team

1. Which keyword declares a class in Java?

class
struct
type
object
Explanation: Java uses `class` to declare classes: `public class Dog { ... }`. `struct` is C/C++, `type` is Go/TypeScript, and `object` is not a declaration keyword in Java.

2. What is the entry point of a Java application?

public static void main(String[] args)
public static void main(String[] args)
function main()
public void start()
static main()
Explanation: The JVM looks for `public static void main(String[] args)`. `public` so the JVM can call it, `static` so no instance is needed, `void` returns nothing, and it takes a String array for command-line args.

3. Which is NOT a primitive type in Java?

int
String
boolean
double
Explanation: Java has 8 primitive types: `byte`, `short`, `int`, `long`, `float`, `double`, `char`, `boolean`. `String` is a class (reference type), not a primitive — even though the language gives it special syntax for literals.

4. What does the `final` keyword mean when applied to a variable?

The variable can only be read once
The variable's value cannot be changed after assignment
The variable is private
The variable is static
Explanation: `final` makes a variable immutable — it can only be assigned once. Applied to a method, it prevents overriding; applied to a class, it prevents subclassing. It's similar to `const` in other languages.

5. Which keyword is used for inheritance?

class Dog extends Animal { }
extends
inherits
implements
: (colon)
Explanation: `extends` is used to inherit from a class: `class Dog extends Animal`. `implements` is for interfaces. The `:` syntax is C++/C#/TypeScript. Java uses keywords `extends` and `implements` explicitly.

6. What is the parent class of all classes in Java?

Object
Class
Base
Parent
Explanation: Every class in Java implicitly extends `java.lang.Object`. It provides methods like `equals()`, `hashCode()`, `toString()`, and `getClass()`. If you don't explicitly extend a class, you extend `Object`.

7. Which statement about `==` and `.equals()` is correct?

They are identical
`==` compares references; `.equals()` compares content (when overridden)
`==` compares content; `.equals()` compares references
Both compare references
Explanation: `==` compares reference identity (do two variables point to the same object?) for objects, and value for primitives. `.equals()` compares content, but only if the class overrides it (String does, StringBuilder doesn't by default). For primitives, use `==`.

More java Quizzes