Array type object of a class is declared like abc a[10]=new abc(); but how to call methods
java array type object of
Collapse
X
-
Tags: None
-
Originally posted by Rajesh ShuklaArray type object of a class is declared like abc a[10]=new abc(); but how to call methods
results in a new object of type abc, not in an array type. btw, an array doesn't
have methods either so you can't invoke them.
Or maybe I misunderstood your question completely in which case you have
to elaborate or rephrase a bit.
kind regards,
Jos -
Originally posted by JosAHThat is not a valid initialization, nor assignment. The 'new abc()' expression
results in a new object of type abc, not in an array type. btw, an array doesn't
have methods either so you can't invoke them.
Or maybe I misunderstood your question completely in which case you have
to elaborate or rephrase a bit.
kind regards,
Jos
abc a[]=new abc[10]; is it correct if yes then how to invoke a methodComment
-
Comment
-
Originally posted by Rajesh Shuklai think it should be like
abc a[]=new abc[10]; is it correct if yes then how to invoke a method
abc object each. Note that there are no abc objects yet, the references don't
'point' at such an object yet. You have to populate the array yourself as in:
[code=java]
abc[] a= new abc[10]; // create a new array
for (int i= 0; i< a.length; i++) // populate the array
a[i]= new abc();
[/code]
As I wrote above: you can't invoke methods on an array; you can invoke methods
on an element of an array of course:
[code=java]
a[3].foo(); // assuming foo() is a method of class abc
[/code]
kind regards,
JosComment
Comment