Results 1 to 2 of 2
  1. #1
    eddieteddie is offline Member
    Join Date
    Sep 2011
    Posts
    5
    Rep Power
    0

    Default Need help reviewing before exam

    Hi everyone

    I have an exam coming up soon, and now is the time for review. I have some questions regarding this review, I will only ask the ones I am so unclear about.

    Java Code:
    How many times will the following do-while loop be executed?
    int x = 11;
    do
    {
    x += 20;
    } while (x > 100);
    a. 0
    b. 1
    c. 4
    d. 5

    The answer is 1, b. Am i right in saying, that this loop has to be executed at least once, and when the compiler reads the "while ...." it stops? Therefore it will be executed at least once?


    Java Code:
    What will be the value of x after the following code is executed?
    int x = 10;
    while (x < 100)
    {
    x += 10;
    }
    a. 90
    b. 100
    c. 110
    d. This is an infinite loop
    The answer is 100, which I do not understand why...

    What is meant by the term void method?

    The scope of a private instance field is
    a. the instance methods of the same class
    b. inside the class, but not inside any method
    c. inside the parentheses of a method header
    d. the method in which they are defined


    The answer is a, but again, I am not sure why it is so.

    When a method's return type is a class, what is actually returned to the calling
    program?
    a. An object of that class
    b. A reference to an object of that class
    c. Only the values in the object that the method accessed
    d. Nothing, the return type is strictly for documentation in this situation


    Last question. B is the answer. Again, need explanation.

    Appreciate any help. Thanks in advance

  2. #2
    pbrockway2 is online now Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default Re: Need help reviewing before exam

    (1) OK, but why does the first one stop when it hits "while(x>100)"?

    (2) Think about the different values x gets as the second loop executes over and over again. Write them down. What makes this loop stop?

    (3) Personally I think the term "void method" means "I'm too lazy to say what I mean, so I just make jargon up as I go along". This is aimed at your teacher not you. There are four things about a method - besides what it actually does! - that are important to the outside world who calls it: (a) the name of the method (otherwise we get the dreaded "cannot find symbol") (b) the number and type of argument it wants (ditto) and (c) the type of thing it returns (otherwise we would not know what to assign the result to) and (d) any exceptions it might throw that we have to catch (like IOException).

    Together these 4 things are called the signature of the method.

    But what happens if the method doesn't return anything? (eg System.out.println() doesn't return anything)

    (4) I'd go for "none of the above" here. And it's really nice when the examiner gets the question wrong (you lose marks for scrawling on the exam paper, but it's nice!) I mean aren't they in scope inside a constructor? Can't they be used - under some circumstances - to initialise other variables: ie not in the scope of any method or constructor?

    (5) What do you pass as arguments to a method? Values, which may be a reference to an object.

    What is returned from a method? Values, which may be a reference to an object.

    What sort of thing can be assigned to a variable? Values, which may be a reference to an object.

    Do you get the pattern?

    Everything is a value (which is either primitive or a reference to an object). Java is boring. But winding up your teacher isn't! Again, "none of the above". When is a value which is a reference to an object of the class not a reference to any object of that class? When it's null! So the real answer is (b) except when it happens that it's not (b).
    Last edited by pbrockway2; 11-10-2011 at 10:11 AM.

Similar Threads

  1. The exam is over!
    By elliotHenry in forum New To Java
    Replies: 2
    Last Post: 06-15-2011, 11:27 PM
  2. Sun exam vouchers
    By aji1729 in forum Java Certification
    Replies: 2
    Last Post: 11-05-2009, 12:43 PM
  3. Preparing for Exam
    By AWPtic in forum New To Java
    Replies: 4
    Last Post: 04-13-2009, 03:34 PM
  4. SUN SCJP 310-065 Exam
    By seedfox in forum Java Certification
    Replies: 0
    Last Post: 03-27-2009, 11:11 AM
  5. SCJP exam dum
    By appoint_raj in forum Java Certification
    Replies: 1
    Last Post: 01-29-2009, 10:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •