-
-
Save krystian-booker/889c24f06f8a66f9efb8b2254f5076f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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