create multiple objects and store information in it through reference variable.
Java Programming Language Class, Object and Methods in java (Article) Class, Object and Methods in java (Program)
29035Program:
// Save it as File name : Student3.java //Object and Class Example: Initialization through reference //create multiple objects and store information in it through reference variable. class Student{ int rollno; String name; } class Student3{ public static void main(String args[]){ //Creating objects Student s1=new Student(); Student s2=new Student(); //Initializing objects s1.rollno=101; s1.name="you"; s2.rollno=102; s2.name="and me"; //Printing data System.out.println(s1.rollno+" "+s1.name); System.out.println(s2.rollno+" "+s2.name); } }
Output:
101 you 102 and me 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.