Tuesday 25 July 2017

Main method inside the class

class Book{  
 int id=10; 
 String name="java";  
  
 public static void main(String args[]){  
  Student s1=new Student();//creating an object of Book
  System.out.println(s1.id);//accessing member through reference variable  
  System.out.println(s1.name);  
 }  
}  



OUTPUT:
10
java

No comments:

Post a Comment