• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

dan's sigle topic--arrays

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class A {public String toString() {return "A";}}
class B {
public static void main(String[] arg) {
A[] a1 = new A[1]; // 1
A[][] a2 = new A[2][]; // 2
A[][][] a3 = new A[3][][]; // 3
a1[0] = new A(); // 4
a2[0] = a2[1] = a1; // 5
a3[0] = a3[1] = a3[2] = a2; // 6
System.out.print(a3[2][1][0]); // 7
}
}
What is the result of attempting to compile and run the above program?

This is a question in dan's single topic exams. The answer is "A". I have a question.
when I compile and run the program, i get a runtime exception saying that there is no such method in the main. Now what does that mean ?
Pls help...
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem could be you might have stored the two classes in one file. If you store the class A in a file A.java and class B in B.java, you do not get any problem and the result is "A".
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
or make class B public and save file as B.java.
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
Save the file as "B.java". (Note the capitalization!)
You need the classname ("B") as the filename to invoke its main() method with the JVM, but you don't need to separate the file into separate files, or change any of the access modifiers.
Regards,
Jeff
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic