Click here to Skip to main content
15,914,820 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
For some reason I can't figure out what is wrong with the following
java file. Any help would be really appreciated. I am sure that it is something simple bit I am at a loss! :confused:

class Test {
  public static void main(String[] args) {
  A a = new A();
  a.print();
  }
}


class A {
  String s;

 A(String s){
   this.s = s;
}

public void print() {
  System.out.print(s);
  }
}
Posted
Updated 28-Jun-10 7:58am
v3

try : :-D

class Test {
public static void main(String[] args) {
A a = new A("World of Warcraft!");
a.print();
}
}
 
Share this answer
 
Just to try to "flesh out" Adrabi's answer:

You created class A with a constructor that takes as input a single string.

Then, when you created your new A, you didn't pass anything in. I assume what you were supposed to pass in was from the argument list, correct?

You may have wanted:

Java
public static void main(String[] args) {
    for (String s: args)
    {
        A a = new A(s);
        a.print();
    }  
}
 
Share this answer
 
Try some thing like this

public class Test {
public static void main(String[] args) {
A a = new A();
a.print();
}
}

becoz, Java need main class is public access specifier
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900