Originally posted by Cindy Glass:
When you created sun1 you made an explicit call to a particular constructor of the super class, so that was used. When you created sun and sun2 you did not call any of the constructors of the superclass, so the no-argument constructor was called for you. Some constructor of every superclass MUST be called before the constructor of the sub-class. Both line 1 and line 6 are caused by that.
Originally posted by Manfred Leonhardt:
It chooses to ignore the second parameter in the add() method
The 'trick' here is that the Container class provides the add methods that are used by the AWT containers. It is up to each layout if it accepts and uses all the given parameters. In the case you have given, the GridLayout doesn't accept any constraints therefore it chooses to ignore the second parameter in the add() method. It is used to confuse you!
By default a GridLayout creates a single row with many columns. Therefore your result will be 2.
Originally posted by Sivalingam Sivasuthan:
Hi jing zhao,
Both (c and d)are Valid Statements, I compiled and got 21 and 10 respectively