+ 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); } }
9 RĂ©ponses
+ 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();
+ 5
do you mean isn't working on the code playground or you don't know the answer
+ 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
+ 2
Yeah, you might want to remove the first line in method foo. Otherwise the method does nothing.
+ 2
Thanks.. I'm new so idk so much about javađđđ„đ„
+ 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.
+ 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);
}
}
+ 1
@brain not working
+ 1
Thanks đ đđđđđ