+ 4

Output is not coming?

class A{ int attr; } class Teat{ static void foo(Aa){ a=new A(); a.attr=2; } public static void main(String [] args ){ A.a=new A(); a.attr=1; foo(a); System.out.println(a.attr); } }

7th Jan 2018, 6:32 AM
Akshaya
Akshaya  - avatar
9 ответов
+ 14
Fixed: https://code.sololearn.com/cYZOHzyil16D/#java 1. You missed space in parameter. Aa should be A a 2. While creating object, use this pattern: class_name object_name = new class_name(); So, it should be A a = new A();
7th Jan 2018, 6:58 AM
Shamima Yasmin
Shamima Yasmin - avatar
+ 5
do you mean isn't working on the code playground or you don't know the answer
7th Jan 2018, 6:35 AM
᠌᠌Code X
᠌᠌Code X - avatar
+ 5
In the "main" method: "A.a" --> "A a" In the "foo" method's parameters: "Aa" --> "A a" "-->" = Change to You just simply made a few simple mistakes when initializing an Instance of a class. Output should be 1
7th Jan 2018, 6:59 AM
Limitless
Limitless - avatar
+ 2
Yeah, you might want to remove the first line in method foo. Otherwise the method does nothing.
7th Jan 2018, 7:26 AM
1of3
1of3 - avatar
+ 2
Thanks.. I'm new so idk so much about java🙁🙁😥😥
7th Jan 2018, 7:32 AM
Akshaya
Akshaya  - avatar
+ 2
@1of3 It wouldn't make a difference in the end either way, because a is not a public variable, nor does it return a value.
7th Jan 2018, 8:53 AM
Limitless
Limitless - avatar
+ 2
Original Code class A{ int attr; } class Teat{ static void foo(A a){ a=new A(); a.attr=2; } public static void main(String [] args ){ A a=new A(); a.attr=1; foo(a); System.out.println(a.attr); } }
7th Jan 2018, 9:59 AM
Tapas Mondal
Tapas Mondal - avatar
+ 1
@brain not working
7th Jan 2018, 7:32 AM
Akshaya
Akshaya  - avatar
+ 1
Thanks 🙏 😊😊😊😊😊
7th Jan 2018, 10:01 AM
Akshaya
Akshaya  - avatar