Sripada Phani

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

Recent posts by Sripada Phani

In your expression != is a boolean comparison operator and = is a assignment operator. Since the precedence of != is greater than =, the expression b1!=b2 will be evaluated first.
ie., b2 = (b1 != b2)
b2 = (false != false)
b2 = false
The answer is -3.
There is difference in representing negative values in binary.
To represent -42 in bits you have to calculate the 2's complement of the number. ie., invert the digits and add 1.
42 = 00101010
Invert bits = 11010101
add 1 = 11010110
ie., -42 = 11010110
-42 >> 4 = 11111101 = -3
Since the most significant bit in the result is 1, again you have to convert it into 2's complement and add the negative sign.
ie, 2's complement = 00000010
1
--------
00000011 = 3
--------
Result is -3.
Hi Jim,
Integral types (byte, short, int, long ) are represented in signed 2's complement integers. Whereas Floating point types float & double values are represented in single precision and double precision formats respectiely. These are IEEE 754 standards.
Which means a Floating type number(may be a double), whose integral part is within the float data type range, may loose its precision once you assign it to a float variable. That's why it is a narrowing coversion.
import java.io.*;
class Test{
public static void main(String a[]) {
float fa=3.03222222F;
double da=3.03222222;
System.out.println("Values fa: "+fa); // prints 3.0322223
System.out.println("Values da: "+da); // prints 3.03222222
}
}
I think this could be reason for not allowing floating type literals to be assigned to float variables.
Regards,
Phani.
When you extend any base class, all the members of base class will get part of the derived class. Based on their access modifiers these memebers get accessed from the new class.
While defining the derived class if you try to change the behaviour of a particular method, with which the signature is already inherited from base class, we call it as overriding. Similarly, if you define any member variable with the same name in derived class we call it as hiding.
In both the cases we are redefining the inherited members. The only difference between these is when you access them. JVM decides which overridden method to call based on the object referrece that curently pointing to. Incase of member fields it's the Class type of the reference it's pointing. Try to run the below program ...
import java.io.*;
class A
{
String str="This String is defined in A";
public void printMsg()
{
System.out.println("This method is defined in Class A");
}
}
public class B extends A
{
String str="This String is defined in B";
public void printMsg()
{
System.out.println("This method is defined in Class B");
}
public static void main(String[] a)
{
B testB=new B();
A testA=testB;
System.out.println(testB.str);//This prints B String
testB.printMsg(); //This prints B Message
System.out.println(testA.str);//But, this prints A String
testA.printMsg(); //This prints B Message
}
}
Any object will get eligible for garbage collection only when the last reference to the obejct is removed.
In this case eventhough reference name is made null, the other referene newestName still pointing to the object. So, the object that was pointed to name was not garbage collected.
Also, all the references will be stored in stack and all the objects that are created by new keyword will be place in heap. When you assign any new reference ( by creating new object), automatically the old reference will be made eligible for garbage collection.
I hope this would answer you question.....
I have writeen the below code to test post fix operator.
public class OpsTest {
public static void main(String a[]) {
int i=2,j=2,k=3;
i=i++ + k;
j=j + k;
System.out.println("i= "+i+" j="+j);
}
}
I expected the value of i would be printed different from j. To my surprise I got both i and j values printed same. Can anyone explain me why the post fix operator was ignored in the first case.