About Question enthuware.ocajp.i.v7.2.1310 :

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

Moderator: admin

Post Reply
ETS User

About Question enthuware.ocajp.i.v7.2.1310 :

Post by ETS User »

Why will it not compile?

Guest

Re: About Question enthuware.ocajp.i.v7.2.1310 :

Post by Guest »

Forget it. I was looking at my answer, not the correct one.

Guest

Re: About Question enthuware.ocajp.i.v7.2.1310 :

Post by Guest »

This example chokes on NetBeans 7.3 beta

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

Re: About Question enthuware.ocajp.i.v7.2.1310 :

Post by admin »

Not sure what you mean by "choke". It compiles and runs fine on notepad + command line.

While NetBeans is a great development environment, we don't recommend it to students while preparing for this exam.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

BEW

Re: About Question enthuware.ocajp.i.v7.2.1310 :

Post by BEW »

If I use a command line or if I use TextEdit it compiles but it doesn't print anything. Even If I supply the value of false in the command line it doesn't print anything for me. I created a class name, installed a main method and played with the ifTest method by removing void and inserting boolean but it never prints anything. I supplied the value of false for flag and created a return statement when I removed void from the ifTest method but it won't print anything. What should be the proper command line entry on a Mac to make this work? What else needs to happen to the code in the question (not the explanation) to make this print 'False False'?

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

Re: About Question enthuware.ocajp.i.v7.2.1310 :

Post by admin »

BEW, If you post your code, I can try to see why it doesn't print anything. But try to compile and run the following code:

Code: Select all

public class TestClass{

   public static void  main(String[] args){
      ifTest(false);
  }

 public static void ifTest(boolean flag){
   if (flag)   //1
   if (flag)   //2
   if (flag)   //3
   System.out.println("False True");
   else        //4
   System.out.println("True False");
   else        //5
   System.out.println("True True");
   else        //6
   System.out.println("False False");
 }

}
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

insider
Posts: 29
Joined: Wed Apr 17, 2013 9:22 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1310 :

Post by insider »

The code in the assignment is indeed valid, everything's fine.

davidkkkk
Posts: 6
Joined: Fri Mar 20, 2015 8:42 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1310 :

Post by davidkkkk »

To save time, when all the "if" tests are the same and the pattern is the same as the given, the output can only be the first one or the last one. You can add 10 more "if" it will be the same ;)

ArpRokz
Posts: 15
Joined: Sun Jan 28, 2018 12:38 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1310 :

Post by ArpRokz »

Why is this compiling successfully ?

The program can never print True True or True False, this should lead to an unreachable code error .. isn't it ?

Can anyone explain to me when to look for the unreachable code error ?

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

Re: About Question enthuware.ocajp.i.v7.2.1310 :

Post by admin »

If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 39 guests