Skip to content

Instantly share code, notes, and snippets.

@krystian-booker
Created August 1, 2023 02:42
Show Gist options
  • Save krystian-booker/889c24f06f8a66f9efb8b2254f5076f1 to your computer and use it in GitHub Desktop.
Save krystian-booker/889c24f06f8a66f9efb8b2254f5076f1 to your computer and use it in GitHub Desktop.
public class Week5Task2 {
// Define a class Student
class Student {
// Student attributes
String name;
int grade;
String major;
// Constructor to initialize all attributes
Student(String name, int grade, String major) {
this.name = name;
this.grade = grade;
this.major = major;
}
// Method to print out the student is studying
void study() {
System.out.println(name + " is studying.");
}
}
public static void main(String[] args) {
// Create an object of the Student class
Student student = new Week5Task2().new Student("Alice", 10, "Computer Science");
// Call the study() method
student.study();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment