File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Errors in Devkas SCJP Exam question 23 of 72 (in assessment) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Errors in Devkas SCJP Exam question 23 of 72 (in assessment)" Watch "Errors in Devkas SCJP Exam question 23 of 72 (in assessment)" New topic
Author

Errors in Devkas SCJP Exam question 23 of 72 (in assessment)

Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
I'm running through Devkas Exam lab and I came across this question:

Exhibit:



Q: Suppose that assertions were enabled successfully. Then what would be he result of compiling and executing this Java program? Which two are possible (Choose two).

Answer options:

  • A. Compilation fails
  • B. Compilation error because of enum declaration
  • C. Compilation error because of the class Tclass
  • D. AssertionError is thrown
  • E. Prints A0 A1 A2 A3 B0 B1 B2 B3
  • F. Prints B1 A1 A2 B3 A3 B2 A4 B4
  • G. Prints B1 B2 A1 B3 A2 A3 B4 A4
  • H. Prints A2 B1 B2 B3 A3 A4 B4 A1
  • I. Prints A1 A2 A3 B1 A4 B2 B3 B4


  • _________________________________________________________________________________________________

    Ok there are a number of issues here, some I will put down to bad proof reading / spell checking but I will point them out.

    Answer C, there is no such class as 'Tclass' its 'TClass'
    Answers E-I have should have colons ':' - Within the first string declaration of the print statements in the go# Methods, yet these are not reflected in the given answers (eg. Answer A should read A:0 A:1 etc)

    However, more importantly none of the answer options offered appear to provide the actual output. Running this in Eclipse with assertions enabled, I recieve this output from three seperate runs:

    Run 1.

    Run 2.

    Run 3.


    Also just to be safe, incase it was Eclipse that was mucking around, I ran from the command line with Java -ea TClass (after compiling) and I recieved the following results (again on three runs):

    Run 1.

    Run 2.

    Run 3.



    Can anyone help on this, perhaps I have missed something in reporducing the code? One point however, that is indeed annoying is the small grammatical / type errors, which seem to be quite frequent. Technically this actually can cause given codes not to compile, even though the answer given may be different.


    be a well encapsulated person, don't expose your privates, unless you public void getWife()!
    Devaka Cooray
    ExamLab Creator
    Saloon Keeper

    Joined: Jul 29, 2008
    Posts: 3013
        
      35

    Stephen Davies wrote:
    Answer C, there is no such class as 'Tclass' its 'TClass'
    Answers E-I have should have colons ':' - Within the first string declaration of the print statements in the go# Methods, yet these are not reflected in the given answers (eg. Answer A should read A:0 A:1 etc)


    Thank you for discovering these two errors. I'll correct it as soon as possible.

    The other things you have mentioned here, are not errors, as you've edited the original code when it posting here. It makes sense if you read the original code (Q:23, Diagnostic Exam):



    Founder of ExamLab and Systemup
    See how I can help you to become an awesome programmer
    Stephen Davies
    Ranch Hand

    Joined: Jul 23, 2008
    Posts: 352
    Thanks for your reply Devaka. I have checked and corrected my version to ensure it matches matches the question exactly.




    my output is now(on three runs):




    ...and from the command line with the -ea flag to be sure:


    Neither of these is offered as an answer option (ignoring the missing colons): Unless I'm missing the point of the question (which two are possible). Can you shed some light on this?

    Devaka Cooray
    ExamLab Creator
    Saloon Keeper

    Joined: Jul 29, 2008
    Posts: 3013
        
      35

    Please look at the for loop which I mentioned in my previous post.



    I couldn't understand that how did you get "A:0" and "B:0" as the output from this program, while the loop iterates from 1-to-4 I think you missed something.
    Stephen Davies
    Ranch Hand

    Joined: Jul 23, 2008
    Posts: 352
    OOps my apologies, there goes me and Eclipse code assist again! Ok with the loop corrections set:



    I get from the command lines with the -ea flag:



    These still don't meet any of the options?

    Devaka Cooray
    ExamLab Creator
    Saloon Keeper

    Joined: Jul 29, 2008
    Posts: 3013
        
      35

    Stephen Davies wrote:
    These still don't meet any of the options?


    The question is "Which two are possible?"
    The "Explanation" part for this question clearly describes how to choose the possible answers. Didn't you read it?
    Stephen Davies
    Ranch Hand

    Joined: Jul 23, 2008
    Posts: 352

    The question is "Which two are possible?"
    The "Explanation" part for this question clearly describes how to choose the possible answers. Didn't you read it?


    Yes Devaka I did read it, however, If this is the core context of the question, I must say in my personal opinion, it is somewhat a vague proposal It would appear any number of combinations is possible. On running the program several times, I have not managed to reproduce any of the potential 'possible' answers and thus, whilst it is true perhaps that some of them are possible so are others not given and to provide a definitive answer is perhaps a tad limiting in scope. Despite this I do thank you kindly for your clarification.
    Devaka Cooray
    ExamLab Creator
    Saloon Keeper

    Joined: Jul 29, 2008
    Posts: 3013
        
      35

    You are right, there are many number of possible combinations with the output. But listing all of them is not possible for a question. However, since the exam expects from you to choose the 'best' answers, keep in mind that it is possible to appear these type questions on the real exam.
    Stephen Davies
    Ranch Hand

    Joined: Jul 23, 2008
    Posts: 352
    Yes I understand these questions may well appear in the exam. However, being that I am content that there are no errors or exceptions thrown this leaves simply the output options. Therefore, in this case, may I be so bold as to inquire as to if there is any flow logic involved in providing the potential oputput options, as I can see no pattern which may provide a 'possible' answer apart from perhaps that each possible output will start with either a A1 or a B1, yet from here I am at a complete loss to choose only two?! Regards
    Angelika Angley
    Ranch Hand

    Joined: Feb 17, 2009
    Posts: 40
    a
    Angelika Angley
    Ranch Hand

    Joined: Feb 17, 2009
    Posts: 40
    You need to look more at threads, especially when two or more threads run simultaneously.
    Here you have 2 threads that run in different instances of the class. Each of them do their own tasks. On CPU you can't do several tasks simultaneously, so one of these threads will come first. It iterates through the loop until it completes OR CPU/JVM decides to switch the task. Thus another thread can begin to do its job even if the first one has not completed its own.
    So the output can be different and it depends on JVM or CPU - whatever... The point is you can see any sequence that is A1A2A3A4B1B2B3B4 or mixed A and B A1B1A2A3B2A4B3B4, but never NEVER you see A2A1A4A3 or smth like this.

    That is, the loop iterates through 1 to 4 and prints 1234, but it can't print smth like 4321 or 1432 (if you program Java of course). So A2 can't come before A1 or A4 before A3.
    Stephen Davies
    Ranch Hand

    Joined: Jul 23, 2008
    Posts: 352
    Yes, I see that but that still leaves Three options to choose, from and if there are many possibilities how does one then choose 2? Your selection and explanation would be interesting if you are willing to provided it.

    Regards

    Angelika Angley
    Ranch Hand

    Joined: Feb 17, 2009
    Posts: 40
    Ok, here we go:

    # A. Compilation fails
    # B. Compilation error because of enum declaration
    # C. Compilation error because of the class Tclass
    # D. AssertionError is thrown
    # E. Prints A0 A1 A2 A3 B0 B1 B2 B3
    # F. Prints B1 A1 A2 B3 A3 B2 A4 B4
    # G. Prints B1 B2 A1 B3 A2 A3 B4 A4
    # H. Prints A2 B1 B2 B3 A3 A4 B4 A1
    # I. Prints A1 A2 A3 B1 A4 B2 B3 B4

    A. We've tested it and know that the code compiles
    B. see A
    C. see A
    D. see A
    E. both iteration loops start with 1 and end with 4, so A0 and B0 can't be in the output.
    F. Looking at A's sequence: A1 A2 A3 A4. Looking at B's sequence: B1 B3 B2 B4 - here B3 comes before B2!!!
    G. Possible output.
    H. Looking at A's sequence: A2 A3 A4 A1. Looking at B's sequence: B1 B2 B3 B4. What is wrong here? A1 came after A4!
    I. Possible output.
    Stephen Davies
    Ranch Hand

    Joined: Jul 23, 2008
    Posts: 352
    Angelika,

    Got it!

    Many thanks
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Errors in Devkas SCJP Exam question 23 of 72 (in assessment)
     
    Similar Threads
    Combinations Algorithm
    Threads(Can someone please explain why the answer to the following questions are unpredictable)
    Operator precedence and associativity confusion........
    Single table two column dependency query