Skip to content

Commit 4028c18

Browse files
Update main_within_class.java
1 parent a4af6b8 commit 4028c18

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

model/main_within_class.java

+15
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
11

2+
//Java Program to illustrate how to define a class and fields
3+
//Defining a Student class.
4+
class Student{
5+
//defining fields
6+
int id;//field or data member or instance variable
7+
String name;
8+
//creating main method inside the Student class
9+
public static void main(String args[]){
10+
//Creating an object or instance
11+
Student s1=new Student();//creating an object of Student
12+
//Printing values of the object
13+
System.out.println(s1.id);//accessing member through reference variable
14+
System.out.println(s1.name);
15+
}
16+
}

0 commit comments

Comments
 (0)