0
I'm getting errors can anyone fix this🤓
public class Test { int i; public Test(int k) { i=k; } public Test(int k, int m) { System.out.println("Hi I am assigning the value max(k, m) to i"); if(k>m) { i=k; } else { i=m; } } } public class Main { public static void main (String args[]) { Test test1 = new Test(10); Test test2 = new Test(12, 15); System.out.println(test1.i); System.out.println(test2.i); } }
3 Answers
+ 2
Try saving your code to the playground and then adding a link to it in your post.
+ 1
You have invalid character in your code as it showing you as error of ex : "\u0000" character .
It may occur if you copied code from a net source.
Remove all those from code by replacing there with empty space again..
Or rewrite your code again..
edit:
program correct only... except invalid characters
+ 1
it works for me
//public
class Test {
int i;
public Test(int k) { i = k; }
public Test(int k, int m) {
System.out.println(
"Hi I am assigning the value max(k, m) to i");
if (k > m) {
i = k;
} else {
i = m;
}
}
}
public class Main {
public static void main(String args[]) {
Test test1 = new Test(10);
Test test2 = new Test(12, 15);
System.out.println(test1.i);
System.out.println(test2.i);
}
}