Creating multiple objects by one type only
Java Programming Language Class, Object and Methods in java (Article) Class, Object and Methods in java (Program)
4964Program:
// Save it as File name : RectangleClassExample2.java // Creating multiple objects by one type only class Rectangle{ int length; int width; void insert(int l,int w){ length=l; width=w; } void calculateArea() { System.out.println(length*width); } } class RectangleClassExample2{ public static void main(String args[]){ Rectangle r1=new Rectangle(),r2=new Rectangle();//creating two objects r1.insert(20,4); r2.insert(4,25); r1.calculateArea(); r2.calculateArea(); } } /* Initialization of refernce variables: Rectangle r1=new Rectangle(), r2=new Rectangle();//creating two objects */
Output:
80 100 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.