Nidhi Bangur

Greenhorn
+ Follow
since Sep 12, 2003
Merit badge: grant badges
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nidhi Bangur

Hi All,

I have got a voucher available with me for the SCBCD exam, which can be used in UK. It is expiring in end of December this year. If anybody from UK is planning to take this exam in near future, please contact me. I can offer this at a discounted price.

Thanks,
Nidhi.
Yes Andres, After your message I rechecked the question. The answers given are the same except that I missed one ";" at the end of both options while writing them here.
I am myself surprised as to how can it be the answer? Any comments from Bert?
Thanks,
Nidhi.
Hi,
Yesterday, I took the mock test included in the CD with Kathy and Bert's book. I came across a question which tested my knowledge of anonymous inner classes.
The question was as follows (The words might not be exactly similar here):
___________________________________________________________________________
Given the following code definition, which two declarations of anonymous inner classes inerted at line 1, will compile successfully?
class Bing{
Bing(String s){
}
Bing(){
}
}
class Bang extends Bing{
Bang(String s){
super(s);
}

Bang(){
super();
}

// Line 1
}
___________________________________________________________________________
There were 2 correct answers to this question which are as follows:
1) Bing b = new Bang(){}
2) Bing b = new Bing(){"Foo";}
I have no problem with option 1 but how is option 2 correct here? I have tried inserting option 2 at line 1 and compiling the code but it doesn't compile and I am sure that this is not a correct syntax of instance initializer as well.
Has anybody else come across this question? Is the question wrong or if the option 2 is still correct, Please let me know how?
Thanks,
Nidhi.
Hi,
Can anybody please point me to good resources/study material links for the topic "Threads" in SCJP? I need something to add/expand my knowledge on this topic acquired by K&B book as I have noticed that the chapter in this book might not be enough.
Any suggestion by SCJP certified programmers is most welcome.
Thanks,
Nidhi.
I agree with Barkat. Thanks Mauline, it was really well explained. I missed the point where Barkat had removed the 'int i' declaration from subclass.
-Nidhi.
I am confused now. According to the code that Barkat posted, it means that if x is initialized in a variable initializer, the value in inherited method is picked up from superclass while if it is declared in instance initializer, its value is picked up from the subclass itself rather than superclass.
Why? What are the rules to know which value of the variable will be used in the inherited (but not overridden) method in a subclass?
Thanks,
Nidhi
Thanks both of you! Its clear now. I did a little bit of experimenting to make the flow clear in my mind. For anybody who is interested, I am pasting the code and results below:

If you run this code, the results are as follows:

i is4
i is6
i is2
true,true,false,16

Now, this makes it very clear. Once you resolve the precedence by putting brackets as suggested by Mika, the expression is evaluated from left-to-right. That's why, "i is4" is printed before "i is6" and "i is2".
[ September 24, 2003: Message edited by: Nidhi Bangur ]
Please refer to my other thread. The question is incomplete here. I think that it got posted by mistake.
Thanks,
Nidhi.
I have come across following question from Dan's operator section tests:
________________________________________________________________________

What is the result of attempting to compile and run the above program?
a. Prints: false,false,false
b. Prints: false,false,true
c. Prints: false,true,false
d. Prints: false,true,true
e. Prints: true,false,false
f. Prints: true,false,true
g. Prints: true,true,false
h. Prints: true,true,true
i. Runtime error
j. Compiler error
k. None of the above
__________________________________________________________________________
Now, based on the operator precedence and operator evaluation rules, '&&' has got a higher precedence than '||'. So, according to me, these should be the order of steps executed at runtime:
  • b is assigned a true value
  • Since b is true, the short-circuit &&operator has to evaluate second operand, i.e. c
  • c is assigned a true value
  • The result of && operand is true
  • Now, the || operator is evaluated. a is assigned a true value.
  • Since a is already true, it returns the value of expression as true
  • Now, x is assigned a true value.


  • Based on this logic, the answer to this question should be 'h' while the correct answer is 'e'. (I have checked it with compiler too). Now, it looks like the operators are being evaluated from left to right but that should only occur when two operators are of equal precedence.
    Why is it behaving this way? If its always supposed to behave this way, what does the higher precedence of && to || imply? When does it usually come into action? Please support with an example.
    Thanks,
    Nidhi.
    I have come across following question from Dan's operator section tests:
    ________________________________________________________________________

    What is the result of attempting to compile and run the above program?
    a. Prints: false,false,false
    b. Prints: false,false,true
    c. Prints: false,true,false
    d. Prints: false,true,true
    e. Prints: true,false,false
    f. Prints: true,false,true
    g. Prints: true,true,false
    h. Prints: true,true,true
    i. Runtime error
    j. Compiler error
    k. None of the above
    __________________________________________________________________________
    Now, based on the operator precedence and operator evaluation rules, '&&' has got a higher precedence than '||'. So, according to me, these should be the order of steps executed at runtime:
    [LIST]
    I too highly recommend Dan's tests. Here's one additional link for topic-wise questions:
    http://www.javaprepare.com/quests/question.html
    -Nidhi.
    Please look at the operator precedence chart at this link: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/expressions.html.
    I don't understand what do they mean by [ ] . (params) in the topmost row under heading "postfix operators". Which three postfix operators do they mean by these three symbols?
    Thanks!
    Hi Barkat,
    I guess that there is one additional explanation to this question well explained at this link: http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html.
    Just to give an overview: You can't use an assert statement here because the compiler will throw an error. Reason: In this particular code, your method has got to return a String object. Thus, either you should write a return statement outside 'Switch' block in which case, you are safe or you should use a 'return' or 'throw' statement in every 'case' statement within 'switch' block. Now, you can't just use an 'assert' statement to replace 'throw' here since the compiler knows that assertions are not always enabled.
    I hope that explains the scenario.
    -Nidhi.