Results 1 to 11 of 11
Thread: I need some help :)
- 03-11-2010, 09:29 AM #1
Member
- Join Date
- Mar 2010
- Location
- Lithuania
- Posts
- 22
- Rep Power
- 0
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); } }When i try to print: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]
vardas
pavarde
amzius
I get:
null
null
0
Why? :)
Thanks :)Last edited by Nerijus; 03-11-2010 at 09:53 AM.
- 03-11-2010, 09:33 AM #2
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
- 03-11-2010, 09:47 AM #3
Member
- Join Date
- Mar 2010
- Location
- Lithuania
- Posts
- 22
- Rep Power
- 0
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 09:50 AM.
- 03-11-2010, 09:49 AM #4
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
- 03-11-2010, 09:51 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,425
- Blog Entries
- 7
- Rep Power
- 17
- 03-11-2010, 09:53 AM #6
Member
- Join Date
- Mar 2010
- Location
- Lithuania
- Posts
- 22
- Rep Power
- 0
Ok now is all code :)
- 03-11-2010, 10:10 AM #7
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
- 03-11-2010, 10:16 AM #8
Member
- Join Date
- Mar 2010
- Location
- Lithuania
- Posts
- 22
- Rep Power
- 0
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
- 03-11-2010, 10:25 AM #9
Yes and that object is totally unrelated to the one inside Zmogus.
It's like doing this:Why doesn't this print 12? It's an Integer too.Java Code:Integer int1 = 12; Integer int2 = null; System.out.println(int2);
Some reading: http://java.sun.com/docs/books/tutor...aOO/index.htmlMath problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 03-11-2010, 10:26 AM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,425
- Blog Entries
- 7
- Rep Power
- 17
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
- 03-11-2010, 10:37 AM #11
Member
- Join Date
- Mar 2010
- Location
- Lithuania
- Posts
- 22
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks