Tuesday, July 14, 2015

Simple Example of Object and Class

class Student1{
 int id;                                             //data member (also instance variable)
 String name;                                 //data member(also instance variable)
 
 public static void main(String args[ ])
{
  Student1 s1=new Student1();           //creating an object of Student
  System.out.println(s1.id);
  System.out.println(s1.name);
 }
}

OUTPUT: 0 null

No comments:

Post a Comment