Q1. CAN INNER CLASSES BE EXTENDED ?IF YES PLEASE TELL ME WHAT IS WRONG WITH THIS CODE.
//problem begins here .compiler is unable to find the default constructor of Inner2
Q2.CAN STATIC METHODS BE OVERRIDED ? ANS . THE ANS TO THIS QUESTION IS PROBABLY NO. BUT STATIC METHODS CAN BE OVERRIDED AS STATIC . BUT IT IS GENERALLY NOT MENTIONED IN EXAM WHETHER TO OVERRIDE THE METHOD AS STATIC OR NON STATIC. SO WHAT SHOULD BE OUR APPROACH TO THE QUESTION.
Q3.CAN THE INBUILT METHODS LIKE SLEEP(),WAIT(),SUSPEND(), NOTIFY () ETC BE SYNCHRONIZED.IF YES PLEASE GIVE ME AN ILLUSTRATION.
Q4.DO THESE METHODS MENTIONED ABOVE IN Q3 RELEASE MONITOR WHEN THEY ARE INVOKED?
Q5 DO SHIFT OPERATORS AUTOMATICALLY WRAPS UP THE VALUE OF PRIMITIVES WHEN REQUIRED? EX. int i=1; i<<31; #ANS IS -2147483648.WHY? IT SHOULD GENEATE AN ERROR "LOSS OF PRECISION." 2 RAISE TO 31 =2147483648 WHICH IS BEYOND THE LIMIT OF int.
Edited by Madhav: Doesn't it look good when indented. Its not very difficult you know.....regds - satya
[This message has been edited by Madhav Lakkapragada (edited January 30, 2001).]
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Joined: Jun 03, 2000
Ravi: Please indent your source code by using the [ code ] tags without the spaces. I did that already in your abv post. Also, please limit the number of qstn in the post to about two or max. three. Not a rule, but a convenience. It makes it easier to answer. regds. - satya
For the answer to Q2, Static methods cannot be overridden to be non-static and vice versa. However, Static methods can be re-declared as static in sub class. Consider the scenario
This program prints out A rather than B. Static methods are not overridden. Overridding has good meaning only in runtime context and not in static context. Hence overridding static methods by another static method donot hold. It is just redeclaration. If this is for SCJP, then overridding static by another static method is not valid.
Joined: Jan 09, 2001
Hi Ravi, Q3: I would think not. Lets suppose they were. We know that both wait and notify are in the Object class. If someone calls wait then nobody can call notify because only one synchronized method can be entered at one time! Q4: Only sleep does NOT release the monitor. Q5: Yes both integers and longs will wrap with shifting. There is no loss of precision. You might get the wrong answer but it will have all the precision of the right answer! This would result in loss of precision: