Code Snippets in JAVA Programming and their OUTPUTS-Day 2
CODE SNIPPETS OUTPUT
ARRAY OF OBJECTS
Concept: Creation of array of objects
class General
{
public int z=0;
}
class Test
{
public static void main (String [] args)
{
General [] g = new General[3];...
More
Code Snippets in JAVA Programming and their OUTPUTS-Day 2
CODE SNIPPETS OUTPUT
ARRAY OF OBJECTS
Concept: Creation of array of objects
class General
{
public int z=0;
}
class Test
{
public static void main (String [] args)
{
General [] g = new General[3];
/*3 General references g[0], g[1] and g[2]
are created and all 3 references are null*/
for(int i = 0; i < g.
length; ++i)
{
g[i] = new General();//Creating General object
g[i].
z=i*10;
}
for(int i = 0; i < g.
length; ++i)
{
System.
out.
println(g[i].
z);
}
}
}
0
10
20
class General
{
RUNTIME ERROR
Exception in thread
"main" java.
lang.
Less