Results 1 to 11 of 11
  1. #1
    Nerijus is offline Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    22
    Rep Power
    0

    Default I need some help :)

    There is two classes:
    First:
    Java Code:
    public class Zmogus {
    
    private Kortele kortele;
    
         public Zmogus( ){
        
          kortele=new Kortele();
        }
    
    public void sukurk(String vardas, String pavarde, int amzius){
      
          kortele.registracija(vardas, pavarde, amzius);
    
         }
    }
    Java Code:
    public class Kortele {
    
       private String vardas;
       private String pavarde;
       private int amzius;
    
    public void registracija(String vardas, String pavarde,int amzius){
    
          this.vardas=vardas;
          this.pavarde=pavarde;
          this.amzius = amzius;
          System.out.println("Kortele jau uzregistruota\n");
    
    }
    public void info(){
        System.out.println("*********************************");
        System.out.println("*"+"Kortele uzregistruota kaip: ");
        System.out.println("*"+"Vardas: " + vardas);
        System.out.println("*"+"Pavarde: " + pavarde);
        System.out.println("*"+"Amzius: " + amzius);
    
        System.out.println("*********************************");
    }
    
    }
    
    [QUOTE]public class Main {
    
    
    
      /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
    Zmogus z = new Zmogus();
    Kortele kort = new Kortele();
    
    z.sukurk("Man","Surename",20);
    
    
    kort.info(); 
    }
    [/QUOTE]
    When i try to print:
    vardas
    pavarde
    amzius

    I get:
    null
    null
    0
    Why? :)
    Thanks :)
    Last edited by Nerijus; 03-11-2010 at 10:53 AM.

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    Where do you print those values? Where do you initialize them?
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Nerijus is offline Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    22
    Rep Power
    0

    Default

    initialize here:
    Zmogus z = new Zmogus();
    Kortele kort = new Kortele();

    z.sukurk("Man","Surename",20);


    kort.info();
    Last edited by Nerijus; 03-11-2010 at 10:50 AM.

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    z.sukurk("Man","Surename",20);

    That doesn't print any values.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Nerijus View Post
    initialize here:
    Please don't make us guess; show us all your code.

    kind regards,

    Jos

  6. #6
    Nerijus is offline Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    22
    Rep Power
    0

    Default

    Ok now is all code :)

  7. #7
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    What is that supposed to do?
    kort.info();

    That is a completely different object from the one inside Zmogus.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  8. #8
    Nerijus is offline Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    22
    Rep Power
    0

    Default

    Yes but this is an object inside Kortele class.
    It suppose to print:
    Vardas
    pavarde
    amzius

    but it's printing:
    Null
    Null
    0
    and i can't find why

  9. #9
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    Yes and that object is totally unrelated to the one inside Zmogus.

    It's like doing this:
    Java Code:
    Integer int1 = 12;
    Integer int2 = null;
    System.out.println(int2);
    Why doesn't this print 12? It's an Integer too.

    Some reading: http://java.sun.com/docs/books/tutor...aOO/index.html
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Nerijus View Post
    Yes but this is an object inside Kortele class.
    It suppose to print:
    Vardas
    pavarde
    amzius

    but it's printing:
    Null
    Null
    0
    and i can't find why
    Your main method creates a Zmogus object; that object creates its own Kortele object and it can set its values by calling sukurk on it. Your main method also creates another Kortele object but you never initialize it. There are two Kortele objects: one that is initialized by the Zmogus object and another one. Finally you want to print the (uninitialized) values of that other object.

    kind regards,

    Jos

  11. #11
    Nerijus is offline Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    22
    Rep Power
    0

    Default

    Year i see now. Thanks :)
    Now i just have to think other way to do this

Posting Permissions

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