Ankur Gupta

Ranch Hand
+ Follow
since Jun 13, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Ankur Gupta

hmm.. actually the semi-colon after the "if()"
if (Test4.this.flag); {
should be the one that is causing the problem (or maybe it was meant to be there to check - eye for detail !) . Try removing and running the ";" after the if().
Oops! Need to be more regular at the ranch, I guess!!
Q29 from javaprepare.com
29.At what stage in the following method does the string "abc" becomes available for garbage collection. Select the one correct answer.

A.Before statement labelled 1
B.Before statement labelled 2
C.Before statement labelled 3
D.Before statement labelled 4
E.Never.
The answer is D. Should it not be C ? i.e. Before stmt 3.
It should be "c".
System.out.println("print"+1*2+3*4);
after print + will behave in a overloaded fashion.
Vivek,
array and Arrays !! It was confusing I guess. Well! now it is clear. Thanks!
Ankur
Shankar
The method returns void. You r not returning anything. You r printing to the console instead. How do u expect it to get concatenated within another print statement.
Try changing the void method to String method and return ("xyz"); instead of the print statement. It should work.
Ankur

Following is from the JLS
10.7 Array Members
The members of an array type are all of the following:
The public final field length, which contains the number of components of the array (length may be positive or zero)
The public method clone, which overrides the method of the same name in class Object and throws no checked exceptions
All the members inherited from class Object; the only method of Object that is not inherited is its clone method

In the API it specifically mentions that java.util.Arrays inherits all the methods of Object including clone. Nowhere does it mention about the above stmt in the JLS.
Any comments !!?
Ankur
Siva,
Hope this helps...
protected void finalize()
throws Throwable
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.
The general contract of finalize is that it is invoked if and when the JavaTM virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output
connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.
The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.
The finalize method is never invoked more than once by a Java virtual machine for any given object.
Any exception thrown by the finalize method causes the iinalization of this object to be halted, but is otherwise ignored.
This was from the Java API. You should always try and have a look at the API and JLS. Writing some code and testing always helps(that goes without saying!!).
Ankur
Walim
Congratulations!! You got a good score. But, stay around to help others..
Ankur
As per the JLS -
A field can be declared final (�4.5.4). Both class and instance variables (static and non-static fields) may be declared
final.
It is a compile-time error if a blank final (�4.5.4) class variable is not definitely assigned (�16.7) by a static initializer (�8.7) of the class in which it is declared.
A blank final instance variable must be definitely assigned (�16.8) at the end of every constructor (�8.8) of the class in which it is declared; otherwise a compile-time error occurs.
Ankur
Following is from the JLS. Hope this clarifies ur doubt.
A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T)((E1) op (E2)), where T is the type of
E1, except that E1 is evaluated only once. Note that the implied cast to type T may be either an identity conversion (�5.1.1) or
a narrowing primitive conversion (�5.1.3). For example, the following code is correct:
short x = 3;
x += 4.6;
and results in x having the value 7 because it is equivalent to:
short x = 3;
x = (short)(x + 4.6);
Ankur
Khalid,
"4" is correct because "99" becomes a String and thereby an Object !!
Ankur
2 and 3 can't be right answers because :
To a vector u can only add Objects - in "2" an int is being added which is not allowed.
There is no add(int i) method for Vector class. You can add only using addElement() - in "3" the method being used is "add(int i)" you could use add(int i, Object o) or add(Object o).
Ankur
[This message has been edited by Ankur (edited July 17, 2000).]
Sdev,
In the statement Severn s = new Severn(); s is the new object formed. But, even before s starts to get created all the corresponding constructors(not always corresponding, sometimes default too!!) in the inheritance hierarchy need to finish executing. Now, in the Base class there is a constructor provided which takes an arg type int. If the object s was being instantiated by a constructor which took int as an arg then it would have been ok(you would have to provide the constructor defn for Severn(int i)).
When there is no explicit declaration of any constructor in a class the default (no args) constructor is provided by default. So, when "s" is being instantiated it looks for the constructor Base() in the parent class. But, that is not there because another constructor is already defined and therefore Base() constructor is not provided by default.
When you are saying Severn s = new Severn(); where is the Severn() constructor ?? It is being provided by default!!
It has been a pretty long explaination. Hope it has been of some use!!
Ankur
Yup!! That is what I meant. Try out this one - add another constructor in this code of urs. Let this new constructor take an arg which is long. Then try executing and see what happens!?
Ankur