The question:
"Which of the following options would be a valid implementation of tester() method?"
I think the following two methods are perfectly valid:
2.public int tester(){ return 0; }
and
4.public String tester(){ return "false"; }
Now, to put them in the switch it is not so good. But otherwise they seem to be perfectly valid implementations of the "tester()" method.
Maybe the question should be changed to something in the likes of "What implementation of the tester method is valid for the code to compile".
/Chrilos
About question enthuware.ocajp.i.v7.2.857
Moderator: admin
-
- Posts: 2
- Joined: Wed Feb 12, 2014 4:17 pm
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About question enthuware.ocajp.i.v7.2.857
Unless explicitly specified, you need to assume that the objective is to provide an answer that will compile.
HTH,
Paul.
HTH,
Paul.
-
- Posts: 35
- Joined: Mon Jul 28, 2014 2:05 am
- Contact:
Re: About question enthuware.ocajp.i.v7.2.857
Although I answered correctly, I don't really understand one thing.
The code
will not compile because of "unreachable statement". This is clear.
But why is this code compile without error?
Why compiler can't determine that the return value of tester() method is constant?
The code
Code: Select all
while(false){
// ...
}
But why is this code compile without error?
Code: Select all
while(tc.tester()){
// ...
}
public boolean tester() {
return false;
}
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About question enthuware.ocajp.i.v7.2.857
That is how the language designers designed it. Return value of a method call is not considered at compile time.
-
- Posts: 7
- Joined: Fri Jan 01, 2016 10:56 pm
- Contact:
Re: About question enthuware.ocajp.i.v7.2.857
Is boolean and Boolean one of the same thing? Since Java is case sensitive , and int and Int are considered different?
So how come these two are same?
So how come these two are same?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About question enthuware.ocajp.i.v7.2.857
boolean and Boolean are different. Int is not a standard java class and has nothing to do with int.
You should read about wrapper classes in java from a good book. Here is a start: http://www.javatpoint.com/wrapper-class-in-java
You should read about wrapper classes in java from a good book. Here is a start: http://www.javatpoint.com/wrapper-class-in-java
Who is online
Users browsing this forum: Google [Bot] and 7 guests