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.
Error in question enthuware.ocajp.i.v8.2.1406
Moderator: admin
-
- Posts: 1
- Joined: Sun Jun 03, 2018 6:19 pm
- Contact:
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: Error in question enthuware.ocajp.i.v8.2.1406
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
Re: Error in question enthuware.ocajp.i.v8.2.1406
There is no mention that
is implicit widening/narowing ?
Code: Select all
int a = 'a';
char c = 6;
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: Error in question enthuware.ocajp.i.v8.2.1406
Well, what do you think they are?
If you like our products and services, please help us by posting your review here.
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
Re: Error in question enthuware.ocajp.i.v8.2.1406
Code: Select all
int a = 'a'; //implicit widening
char c = 6; //implicit narrowing
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: Error in question enthuware.ocajp.i.v8.2.1406
Correct
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Bing [Bot] and 49 guests