Originally posted by Marc Wentink:
Actually this is confusing me even more:
Originally posted by Vivian Josh:
No, I fell for the same trap
I checked all 4 answers because it evaluated to 1111. But only ans true is the given one and in that case x becomes 100 . (Initial x =0 and all other cases were in if() statement.)
Originally posted by dolly shah:
Yeming, Thanks for explanation. But Is this not a method call before supertype constructor has been called?
Animal(){
this(getFood());
System.out.println("No-arg constructor completes");
}
Can you explain little more? I am not getting exactly.
Originally posted by sumi selva:
Hi,
I tried the following code
class Test {
static int x ; ---> line 1
x = 3;
public static void main(String[] args) {
}
}
even if I substitute int x (or) final int x (or) final static int x
I get a compile error.
Should a instance variable always be a compile time constant.cant we assign them values at runtime.
Thanks,
Sumi
Originally posted by Raghavan Muthu:
When it comes to the initialiazing of superclass through constructor chaining, the instance variable "i" of superclass has to get the value by calling the method "getFeet()" (as per the code). Obviously, you can call ONLY the static method(s) during or within the constructor because to invoke an instance method, there is "NO" object existing and thats what you are doing it now.
Originally posted by dolly shah:
Thanks both of you.
But I am confuse about Constructor chaining which is written in K & B book, chapter-2, page-128. It shows, constructor invoked then instance variable then constructor completes. I am not getting this chaining.
Can you explain please?