File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ package OOPS ;
2
+
3
+ import java .util .Scanner ;
4
+
5
+ public class ArrayOfObject {
6
+ int age ;
7
+ String name ;
8
+
9
+ ArrayOfObject (int age , String name ) {
10
+ this .age = age ;
11
+ this .name = name ;
12
+ }
13
+
14
+ @ Override
15
+ public String toString () {
16
+ return STR ."ArrayOfObject{\n age=\{age }, \n \t name='\{name }'\n }" ;
17
+ }
18
+
19
+ public static void main (String [] args ) {
20
+ Scanner sc = new Scanner (System .in );
21
+ int size = sc .nextInt ();
22
+ ArrayOfObject [] arr = new ArrayOfObject [size ];
23
+ for (int i = 0 ; i < arr .length ; i ++) {
24
+ sc .nextLine ();
25
+ System .out .println ("Enter name " );
26
+ String name = sc .nextLine ();
27
+ System .out .println ("Enter age " );
28
+ int age = sc .nextInt ();
29
+ arr [i ] = new ArrayOfObject (age , name );
30
+ }
31
+
32
+ for (ArrayOfObject a : arr ) {
33
+ System .out .println (a );
34
+ }
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments