Results 1 to 6 of 6
Thread: whats wrong with my code
- 07-14-2011, 08:12 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 7
- Rep Power
- 0
whats wrong with my code
i have created a constructor in my class and initialize variables inside the construct
what i want is when i ll call a method and pass a argument while creating a object to constructor , the method should print my new values
the code is
Java Code:class test10 { int a = 5; int b; public test10(int a , int b) { this.a = 10 ; this.b = 50 ; //System.out.println(a); //System.out.println(b); //System.out.println(this.a); //System.out.println(this.b); } public void show() { System.out.println(this.b); System.out.println(this.a); } public static void main(String[] args) { test10 t = new test10(56 , 80); t.show(); } }
- 07-14-2011, 08:24 PM #2
What's your question? What's output are you expecting? What do you get instead? Have you stepped through this with a debugger to figure out what's going on?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 07-14-2011, 08:29 PM #3
Member
- Join Date
- Jul 2011
- Posts
- 27
- Rep Power
- 0
Try this...
Im only learning myself but it compiles and runs ok. I think it was because you gave a and b values in the public test10. but i could be wrong so feel free to correct me
Java Code:class test10 { int a; int b; public test10(int x , int y) { a = x ; b = y ; //System.out.println(a); //System.out.println(b); //System.out.println(this.a); //System.out.println(this.b); } public void show() { System.out.println(this.b); System.out.println(this.a); } public static void main(String[] args) { test10 t = new test10(56 , 80); t.show(); } }Last edited by mrbrendano; 07-14-2011 at 08:36 PM.
- 07-14-2011, 08:40 PM #4
Please let the OP figure out his assignment himself.
Spoon feeding code will not help a student learn how to write code.
If you do post code, be sure to add comments describing what you have done, why you have done it and any extra considerations. In other words help the OP to fully understand your code.
- 07-14-2011, 09:10 PM #5
Member
- Join Date
- Jul 2011
- Posts
- 27
- Rep Power
- 0
my bad norm. wont happen again
- 07-15-2011, 02:06 AM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
Similar Threads
-
Whats wrong with my code
By zit1343 in forum New To JavaReplies: 9Last Post: 01-24-2011, 01:06 AM -
whats wrong with this code
By hamzeeco in forum Java AppletsReplies: 2Last Post: 12-31-2010, 02:19 PM -
whats wrong with my code?
By beandip408 in forum New To JavaReplies: 6Last Post: 11-03-2010, 12:01 AM -
Whats wrong with this code???
By javanew in forum New To JavaReplies: 4Last Post: 03-28-2010, 05:46 PM -
Whats wrong with this code?
By bbtgirl in forum New To JavaReplies: 2Last Post: 02-25-2009, 03:51 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks