Skip to content
Learn Netverks

Lesson

Step 12/36 33% through track

classes-objects

Classes and objects

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Classes and objects: the syntax, APIs, and habits you need before advancing in Java.

Teams ship Classes and objects on every Java codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Classes and objects in contexts like: Spring Boot APIs, banking systems, Android (with Kotlin), and batch/data pipelines on the JVM.

Write Java with a public class (lessons use Main), click Run on server—the dev runner runs javac then java; fix compile errors from stderr (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

A class is a blueprint; an object is a runtime instance created with new. If you know PHP or JavaScript classes, Java OOP is stricter: fields have types, access modifiers matter, and everything lives in a class (even main).

Defining and using a class

class User {
    String name;
    void greet() {
        System.out.println("Hi, " + name);
    }
}

User u = new User();
u.name = "Ada";
u.greet();

Non-public helper classes can live in the same file as Main; only one public top-level class per file.

Reference semantics

User a = new User(); User b = a; — both reference the same object; mutating through b affects a.

Important interview questions and answers

  1. Q: Class vs object?
    A: Class is the template; object is a heap instance with its own field values.
  2. Q: new keyword?
    A: Allocates memory and calls the constructor; returns a reference.

Self-check

  1. What operator creates an object?
  2. How does Java OOP differ from JavaScript prototypes?

Tip: Compare with PHP OOP—Java fields need types; prefer private fields plus methods over public mutable state.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • new vs reference?
  • this keyword when?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump