Results 1 to 6 of 6

Thread: what the outPut

  1. #1
    alksam is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Default what the outPut

    in this program when you compile it, don't give u any problem. but when you run, doesn't work,

    public class Test {

    String text;

    public void Test(String s) {
    this.text = s;
    }

    public static void main (String[ ] args) {
    Test test = new Test("ABC");
    System.out.println(test);
    }
    }

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Describe "doesn't work", as I can guarantee that it produces exactly what you've told it to produce.

    P.S. You probably meant "test.text".

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default A couple of things...

    First, remove the "void" from your constructor. As far as I know, constructors never return anything (FYI... it wouldn't compile for me with that void there).
    Second, as masijade mentioned, use test.text in your println statement.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Yes, the following is wrong with instantiate.

    Java Code:
    public void Test(String s) {

  5. #5
    alksam is offline Member
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Default

    thank u for all, i knew where is the problem

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. different output
    By pro85 in forum Java Applets
    Replies: 6
    Last Post: 08-05-2008, 02:42 PM
  2. What will be output and why
    By huma in forum Threads and Synchronization
    Replies: 4
    Last Post: 06-26-2008, 11:14 PM
  3. Why the output is always zero
    By mehrotra.chitij in forum New To Java
    Replies: 12
    Last Post: 04-25-2008, 05:05 AM
  4. output
    By Camden in forum New To Java
    Replies: 3
    Last Post: 12-01-2007, 11:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •