Tutorials

Java OOP Tutorial

All Tutorials Learning Tools Login

Java OOP Tutorial · Chapter 10 of 10

OOP Practice Path

Turn OOP reading into working drills.

Use Practice Mode lessons OOP Multiple Files and OOP MySQL CRUD.

Challenge ideas: add yearLevel, create a second object, or insert a third student record.

Practice reminder Try it Yourself »
public class Main {
    public static void main(String[] args) {
        Student student = new Student("Practice Student", "BSCS");
        student.introduce();
        System.out.println("Ready for OOP Practice Mode.");
    }
}
Student.java
public class Student {
    private String name;
    private String course;

    public Student(String name, String course) {
        this.name = name;
        this.course = course;
    }

    public String getName() {
        return name;
    }

    public String getCourse() {
        return course;
    }

    public void introduce() {
        System.out.println("Hello, I am " + name + " from " + course + ".");
    }

    public void displayProfile() {
        System.out.println("Name: " + name);
        System.out.println("Course: " + course);
    }
}

Classroom Tips

  • Tutorial teaches ideas. Practice proves you can use them.