About question enthuware.ocajp.i.v7.2.857

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Chrilos
Posts: 2
Joined: Wed Feb 12, 2014 4:17 pm
Contact:

About question enthuware.ocajp.i.v7.2.857

Post 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

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Unless explicitly specified, you need to assume that the objective is to provide an answer that will compile.

HTH,
Paul.

pfilaretov
Posts: 35
Joined: Mon Jul 28, 2014 2:05 am
Contact:

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

Post 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?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

That is how the language designers designed it. Return value of a method call is not considered at compile time.

Simarpreet Singh
Posts: 7
Joined: Fri Jan 01, 2016 10:56 pm
Contact:

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

Post 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?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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

Post Reply

Who is online

Users browsing this forum: No registered users and 37 guests