You are on page 1of 2

public class Student {

private String name;

private int age;

public Student() {

name = "No name yet.";

age = 0;

public Student(String name, int age) {

this.name = name;

this.age = age;

// Overloaded constructor

public Student(String name) {

this.name = name;

this.age = 0; // Default age if not provided

public void studentInfo() {

System.out.println("Name: " + name);

System.out.println("Age: " + age);

public static void main(String[] args) {

// Instantiate an object using the overloaded constructor

Student student1 = new Student("Allan");

student1.studentInfo();
// Instantiate an object using the original constructor

Student student2 = new Student("Brenan", 20);

student2.studentInfo();

You might also like