Demo.java
1public class Demo {
2 public static void main(String[] args) {
3 Student s1 = new Student();
4 Student s2 = new Student();
5
6 s1.name = "Aditya";
7 s1.age = 28;
8 s1.rollNumber = 101;
9 s1.college = "IIT Guwahati";
10
11 s2.name = "Rohit";
12 s2.age = 28;
13 s2.rollNumber = 102;
14 s2.college = "IIT Guwahati";
15
16 s1.markAttendance();
17 s2.markAttendance();
18
19 s1.print();
20 s2.print();
21 }
22}
23
24class Student {
25 String name;
26 int age;
27 int rollNumber;
28 String college;
29
30 void markAttendance() {
31 System.out.println("Attendance marked by " + name);
32 }
33
34 void print() {
35 System.out.println(name + " , " + age + " , " + rollNumber + " , " + college);
36 }
37}>_ CONSOLE
Waiting for output...
Stack Memory
Stack is empty
Heap Memory
Heap is empty