Win a copy of Modern frontends with htmx this week in the Spring forum!

alok Jain

+ Follow
since Aug 24, 2007
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by alok Jain

When we use wild card notation with extends we cannot add ANYTHING . That is readonly . Now when you use wild card notation with super you can add to the collection . Since String is a Object you are allowed to add it.
hi ,
[0-9a-z]+ means one or more occurances of anything between 0 to 9 OR a to z . Also the order does not matter .
Hi ,
(i.equals (42)) is true
reason :
42 can be boxed to Integer and then the equals method will compare the value both the Integer objects are holding .

D) cannot be correct . equals method in the Integer class checks the instance's type using instanceof operator .
Hi ,
From the Java Language Specification
"There is also a special null type, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.
I did not get what you meant by "A" . The comparison will not result in equal . They are not equal as the objects being compared belong to different classes . In this case the equals method in the String Class is being invoked . This will result false as the instanceof check fails.

From the String class in jdk 1.5_06
public boolean equals(Object anObject) {
if (this == anObject) {
return true;
if (anObject instanceof String) {
String anotherString = (String)anObject;
int n = count;
if (n == anotherString.count) {
char v1[] = value;
char v2[] = anotherString.value;
int i = offset;
int j = anotherString.offset;
while (n-- != 0) {
if (v1[i++] != v2[j++])
return false;
return true;
return false;
The output you are getting is first thread completes and then second thread starts . But this cannot be guareenteed. So the answers D,E are correct.
Hi ,
suppose you have a expression like
int x= 1 , y = 2 , z = 0;
z = x++ + ++y ;

now what happens is :
1) first the expression on the right hand side is evaluated as below :
a) first all the prefix operators are applied to the operands .
here in the above example since y has prefix operator y becomes 3 .

2) Now the expression is evaluated and the result of the expression is kept in a temporary location.
3) If the operands have any postfix operator that is evaluated for that operand .

4) Now the assignment to the LEFT HAND SIDE takes place . The LEFT HAND SIDE is given the value evaluated in the step 2 mentioned above .

..If you apply above rules correctly you should be able to get that the value of i as 2 .
let us see what happens for
int i = 1;
i= i++;

if you follow my rules above then
Step 1) Not applicable
Step 2) the value of the expression is 1.
Step 3) the value of i becomes 2
Step 4) the value of the expression evaluated to 1 is now assigned to i ( overwriting the value 2 )
Hi ,
Yeah we cannot say for sure because in the called method the references to the Q object can still be maintained and the method returns ..for example a new thread might be created and it has the references to the Q objects unless we know the implementation we cannot say what will be the state of the objects..
Hi Gitesh,
The following three are common to TreeSet and HashSet

*Each element must be unique.
*Contains no duplicate elements.
*Elements are not key/value pairs.

Now the last feature is where these differ :

Accessing an element can be almost as fast as performing a similar operation on an array.

This feature makes the choice to be HashSet .

If you are wondering why ..then to give you a hint ...

The HashSet is very fast for searching because of the the hashing .Well this is true for any Hash<table , Map , Set > .
The elements in the TreeSet are kept in a sorted fashion.
Hi ,
Your code compiles because the compiler sees that the base (reference ) can potentially have a Sub Object , so it allows your code to compile .
Now at runtime when you have a Base object referred by base (reference ) ,
which you are trying to cast to a Sub type , so your code gives the exception .

2. is this always the case that whenever we downcast a parent class we will get runtime error?

You cannot assign a Base Object to a reference of a Sub Type . never .

I think you need to understand what is a
1) Object ( not the java.lang.Object ).
2) Reference to an Object .