Thursday 12 June 2014

Program to use object as an array

import javax.swing.JOptionPane;
class d
{
int a;
public void ink()
{
System.out.print("\nenter number");
a=Integer.parseInt(JOptionPane.showInputDialog(" "));
}
public void outk()
{
System.out.print("\n "+a);
}
}


public class objectasarray {
public static void main(String[] args) {
d []t=new d[5];
for(int i=0; i<5; i++)
{
t[i]=new d();
t[i].ink();

}
for(int i=0; i<5; i++)
t[i].outk();
}

}
output:

enter number 1
enter number 2
enter number 3
enter number 6
enter number 5 
1
2
3
6
5

No comments:

Post a Comment

SAY HELLO!!