sankar sivassoupramanime

Greenhorn
+ Follow
since Jan 03, 2001
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 sankar sivassoupramanime

thanks buddy!!!
23 years ago
Friends,
Here goes the code,
class a{
public static void main(String args[]){
int a[][]= new [2][];
System.out.println(a[0][0]);
}}
Output;
null
In this case i suppose it should print 0. Why it doesn't happen? Would be happy if you give a simple example for three dimentional array.
thanks folks!!
23 years ago
Friends,
Please see the code below and explain me the reason for the output
class Base{
int i=10;

Base(){
amethod();
}
void amethod() {
System.out.println("In Base " + i);
}
Base(int b) {
System.out.println("In Base one parm con" + b);
}
}

class Child extends Base{
int i=15;
Child(){
System.out.println("In default child " +i);
}
Child(int c){
System.out.println("In child one parm con" + c);
}
void amethod() {
System.out.println("In Child " +i);
}
public static void main(String ar[]) {
Base test = new Child();
System.out.println("In main " + test.i);
test.amethod();
}
}
Output:
In Child 0
In default child 15
In main 10
In Child 15
I would like to know why i get "In main 10" instead of
" In main 15"
I'm assigning the reference of the Child to test. It has to take the value of i in the child, but it takes from the Base.
Will you please explain me why this happens.
Thanks for your answers
sankar
23 years ago
Ameen,
You can't compare NaN value direclty in java and if you do it ALWAYS evaluates to false. If you would like to compare using NaN then try this out,
class doublenan
{
public static void main(String args[]){
Double a=new Double(Double.NaN);
Double b=new Double(Double.NaN);
double d =a.floatValue();
if (Double.isNaN(d))
{
System.out.println("true");
}
else
System.out.println("false");
if (a.equals(b))
{
System.out.println("true");
}
else
System.out.println("false");
}
};
You will get as true,true
Hope are clear now!
Ameen,
You can't compare NaN value direclty in java and if you do it ALWAYS evaluates to false. If you would like to compare using NaN then try this out,
class doublenan
{
public static void main(String args[]){
Double a=new Double(Double.NaN);
Double b=new Double(Double.NaN);
double d =a.floatValue();
if (Double.isNaN(d))
{
System.out.println("true");
}
else
System.out.println("false");
if (a.equals(b))
{
System.out.println("true");
}
else
System.out.println("false");
}
}
You will get as true,true
Hope are clear now!
You are right!!!
hi,
I believe that the statements reflect the modifiers of the variable in an interface. Please note that the variables declared inside are implcicitly final and static. So there is only one copy is created.
hi,
It is not necessary that you have to do an explicit cast in this case. As character is 16 bits and integer is 32 bits, the integer can hold the value of 16 bits. So there is no need of the statement
(int)c;
But if you want to store the value of int to a char then you need to do an explicit cast as
c = (char)I; // if I is an integer and c is a character
Also note that when converting a char to an int the value is always positive as char is unsigned.
23 years ago
Hi,
I have a class C1 in package p1 and compiling the class i get no error. I wrote another class C2 which extends C1 and stored in the same directory as C1. Getting the error as
"superclass p1.C1 of class p1.C2 not found".
Think i have to set classpath but i'm not sure how to do it.
Will you please help me out!
Thanks
23 years ago
Thanks a lot buddies for helping to clear my doubt!!!
Thanks Beilin!!!
23 years ago
Hi Marilyn,
Thanks for the info. But explain me the following,
if we say,
case :1
int i =0;
i = ++i;
System.out.println(i);
it gives the result as 1;
refering the book it says that the value of i is incremented and then assigned. Which is true as we get the value 1.
But if we say,
case 2:
int i =0;
i = i++;
System.out.println(i);
it gives the result as 0;
refering the book it says that the value of i is assigned and then incremented. But my question is when the value of i is incremented. I have displayed the value in the next line and it only gives 0.
Tried the same code in language C but the value i get for the second case is 1. Will you please explain this.

23 years ago
class ranch{
public static void main(String argds[])
{
int j=0,k=0;
j=j++;
System.out.println(j);
k = j++;
System.out.println(j);
System.out.println(k);
}
}
Compiling and running the code i get the answer as 0,1,0
Would like to know how this happens. What is the use of post increment in real situation.
Thanks for your replies.
23 years ago