File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Mock Exam Errata and the fly likes Jtips Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Jtips Question" Watch "Jtips Question" New topic

Jtips Question

Thiru Narayanan

Joined: Apr 30, 2001
Posts: 23
public class Q1 {
static void processorB() {
System.out.println(" is a boolean Operator.");

static Q1 processorA(){
Q1 q=null;
if (("java").startsWith("null"))
return q;
return null;

static {

public static void main(String[] args) {
The answer for this program is given as "true is a boolean operator". Can anyone please explain how it comes?
This one is one of the toughest I have encountered so far! I thought the answer should be only "is a boolean operator"
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Thiru,
The first thing that gets run on class loading is any static blocks. Your code has a static block that prints out a boolean value.
"Java".startsWith( "" )
Since the string "Java" does start with "" (empty string) the result is true. That is why your output starts with the string "true".
You seem to understand the rest so I won't bother to continue ...
Thiru Narayanan

Joined: Apr 30, 2001
Posts: 23
Thank you Manfred.
I was under the impression that the static block will just print the empty string. Overlooked the fact that startsWith() method returns a boolean value.
I agree. Here's the link:
subject: Jtips Question
It's not a secret anymore!