Object and Class Example: main outside class

Java Programming Language / Class, Object and Methods in java

1538

Program:

 
// Save it as File name : Student1.java

class Student{
 int rollno=1;
 String name="atnyla";
}

class Student1{
 public static void main(String args[]){
	 
  Student s1=new Student();
  System.out.println(s1.rollno);
  System.out.println(s1.name);
 }
}

// Object and Class Example: main outside class

  

Output:

1
atnyla
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.