Aneesh Kannel

Greenhorn
+ Follow
since Oct 23, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Aneesh Kannel

Can you please tell me whats wrong with my code?
I am Getting an Error like this.
/*
Error

WrapperTest.java:7: cannot find symbol
symbol : class valueOf
location: class java.lang.Integer
Integer i3=new Integer.valueOf("101011",2);
^
WrapperTest.java:8: cannot find symbol
symbol : class valueOf
location: class java.lang.Integer
Integer i4=new Integer.valueOf("101011",8);
^
WrapperTest.java:9: cannot find symbol
symbol : class valueOf
location: class java.lang.Integer
Integer i5=new Integer.valueOf("101011",16);
^
WrapperTest.java:23: cannot find symbol
symbol : class valueOf
location: class java.lang.Float
Float f3=new Float.valueOf("3.14f");
^
4 errors

*/
Coding Below

class WrapperTest
{
void inttest()
{
Integer i1=new Integer(42);
Integer i2=new Integer("42");
Integer i3=new Integer.valueOf("101011",2);
Integer i4=new Integer.valueOf("101011",8);
Integer i5=new Integer.valueOf("101011",16);

System.out.println(i1);
System.out.println(i2);
System.out.println(i3);
System.out.println(i4);
System.out.println(i5);

}

void floattest()
{
Float f1=new Float(3.14);
Float f2=new Float("3.14");
Float f3=new Float.valueOf("3.14f");

System.out.println(f1);
System.out.println(f2);
System.out.println(f3);
}

void booleantest()
{
Boolean b1=new Boolean(false);
Boolean b2=new Boolean("false");

System.out.println(b1);
System.out.println(b2);
}

public static void main(String arr[])
{
WrapperTest wt=new WrapperTest();
wt.inttest();
wt.floattest();
wt.booleantest();
}
}
17 years ago
Can you please tell me whats wrong with my code?
I am Getting an Error like this.
/*
Error

WrapperTest.java:7: cannot find symbol
symbol : class valueOf
location: class java.lang.Integer
Integer i3=new Integer.valueOf("101011",2);
^
WrapperTest.java:8: cannot find symbol
symbol : class valueOf
location: class java.lang.Integer
Integer i4=new Integer.valueOf("101011",8);
^
WrapperTest.java:9: cannot find symbol
symbol : class valueOf
location: class java.lang.Integer
Integer i5=new Integer.valueOf("101011",16);
^
WrapperTest.java:23: cannot find symbol
symbol : class valueOf
location: class java.lang.Float
Float f3=new Float.valueOf("3.14f");
^
4 errors

*/
Coding Below

class WrapperTest
{
void inttest()
{
Integer i1=new Integer(42);
Integer i2=new Integer("42");
Integer i3=new Integer.valueOf("101011",2);
Integer i4=new Integer.valueOf("101011",8);
Integer i5=new Integer.valueOf("101011",16);

System.out.println(i1);
System.out.println(i2);
System.out.println(i3);
System.out.println(i4);
System.out.println(i5);

}

void floattest()
{
Float f1=new Float(3.14);
Float f2=new Float("3.14");
Float f3=new Float.valueOf("3.14f");

System.out.println(f1);
System.out.println(f2);
System.out.println(f3);
}

void booleantest()
{
Boolean b1=new Boolean(false);
Boolean b2=new Boolean("false");

System.out.println(b1);
System.out.println(b2);
}

public static void main(String arr[])
{
WrapperTest wt=new WrapperTest();
wt.inttest();
wt.floattest();
wt.booleantest();
}
}
17 years ago
The first line in a Constructor must be a call to super() or a call to this().

So can the this() be used in no arg Constructor.

Example can this() be used in any of the below two Constructors...
--------------------------------------------------------------------------
class Birds
{
Birds()
{
//super(); implicitly invoked...
System.out.println("Bird Constructor Invoked");
}

void Bird()
{
System.out.println("Bird Method Invoked");
}

}

class Parrot_noarg_Constructor extends Birds
{
Parrot_noarg_Constructor()
{
//super(); implicitly invoked...
System.out.println("Parrot Constructor Invoked");
}

void Parrot()
{
System.out.println("Parrot Method Invoked");
}

public static void main(String arr[])
{
Parrot_noarg_Constructor e=new Parrot_noarg_Constructor();
e.Bird();
e.Parrot();
}
}
"Files with no public classes can have a name that
does not match any of the classes in the file."

Well I have read this from the Java SCJP Study Guide

Please explain to me this with Example.
17 years ago