Page 1 of 1

About question enthuware.ocajp.i.v7.2.857

Posted: Wed Feb 12, 2014 4:24 pm
by Chrilos
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

Re: About question enthuware.ocajp.i.v7.2.857

Posted: Wed Feb 12, 2014 9:11 pm
by admin
Unless explicitly specified, you need to assume that the objective is to provide an answer that will compile.

HTH,
Paul.

Re: About question enthuware.ocajp.i.v7.2.857

Posted: Wed Sep 03, 2014 2:08 am
by pfilaretov
Although I answered correctly, I don't really understand one thing.
The code

Code: Select all

while(false){
  // ...
}
will not compile because of "unreachable statement". This is clear.

But why is this code compile without error?

Code: Select all

while(tc.tester()){
  // ...
}

public boolean tester() {
  return false;
}
Why compiler can't determine that the return value of tester() method is constant?

Re: About question enthuware.ocajp.i.v7.2.857

Posted: Wed Sep 03, 2014 7:11 am
by admin
That is how the language designers designed it. Return value of a method call is not considered at compile time.

Re: About question enthuware.ocajp.i.v7.2.857

Posted: Wed Jan 13, 2016 9:58 am
by Simarpreet Singh
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?

Re: About question enthuware.ocajp.i.v7.2.857

Posted: Wed Jan 13, 2016 10:04 am
by admin
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