Page 1 of 1

Error in question enthuware.ocajp.i.v8.2.1406

Posted: Wed Jul 18, 2018 5:36 pm
by Kyi Min Han
What will the following code print when run?
public class Noobs {
public void m(int a){
System.out.println("In int ");
}
public void m(char c){
System.out.println("In char ");
}
public static void main(String[] args) {
Noobs n = new Noobs();
int a = 'a';
char c = 6;
n.m(a);
n.m(c);
}
}

Web test show me answer is “In int , In char” even if program can’t compile.

Re: Error in question enthuware.ocajp.i.v8.2.1406

Posted: Wed Jul 18, 2018 8:05 pm
by admin
Assuming that you are talking about 2.1406, the question and the answer are correct. Please make sure you have typed the code exactly as given in the question.

Re: Error in question enthuware.ocajp.i.v8.2.1406

Posted: Sat Sep 15, 2018 11:06 am
by flex567
There is no mention that

Code: Select all

int a = 'a';
char c = 6;
is implicit widening/narowing ?

Re: Error in question enthuware.ocajp.i.v8.2.1406

Posted: Sat Sep 15, 2018 11:26 am
by admin
Well, what do you think they are?

Re: Error in question enthuware.ocajp.i.v8.2.1406

Posted: Sat Sep 15, 2018 12:02 pm
by flex567

Code: Select all

int a = 'a'; //implicit widening
char c = 6; //implicit narrowing

Re: Error in question enthuware.ocajp.i.v8.2.1406

Posted: Sat Sep 15, 2018 12:34 pm
by admin
Correct :)