src/
└── studentinfo/
         └── Student.java
└── Main.java

 

package studentinfo;

public class Student {
private String name;
private int rollNo;
private double marks;

// Constructor
public Student(String name, int rollNo, double marks) {
this.name = name;
this.rollNo = rollNo;
this.marks = marks;
}

// Method to print student details
public void printDetails() {
System.out.println(“Name: ” + name);
System.out.println(“Roll No: ” + rollNo);
System.out.println(“Marks: ” + marks);
}
}

 

import studentinfo.Student;

public class Main {
public static void main(String[] args) {
// Create an instance of Student from the studentinfo package
Student student = new Student(“Alice”, 101, 89.5);

// Print student details
student.printDetails();
}
}

Compile

javac studentinfo/Student.java
javac Main.java

To execute

java Main


Leave a Reply

Your email address will not be published. Required fields are marked *