When I compile the following Gary.java program, I get an error stating: Incompatible type for declaration. Can't convert java.lang.String to string. Why??? Here's my simple Gary.java program:
public class Gary { static public void main(String args[]) { string tmp = "boy"; } } Also, what class(if any) are the primitives such as integer in? Insn't everything a subclass of class Object?
Bill Graf
Greenhorn
Joined: Apr 07, 2001
Posts: 4
posted
0
String needs a capital S.
Originally posted by Gary Farms: When I compile the following Gary.java program, I get an error stating: Incompatible type for declaration. Can't convert java.lang.String to string. Why??? Here's my simple Gary.java program:
public class Gary { static public void main(String args[]) { string tmp = "boy"; } } Also, what class(if any) are the primitives such as integer in? Insn't everything a subclass of class Object?
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
Capitalize the word String. Java is case sensitive. Primitives are called primitives because they are not objects. So you will not find them in any class. Java is ALMOST a pure OO language, except for the primitives which were allowed for efficiency, and for the String Literal behavior which is a shortcut and adds efficiency, and arrays which have some specific non-OO behavior other than that it is completely OO. Notice that C++ is not a pure OO language, VB is not even CLOSE, etc. There ARE a few pure OO languages out there though.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Christine Alfano
Greenhorn
Joined: Jan 30, 2001
Posts: 1
posted
0
In order to declare a String the 'S' must be capitalized. Make the change and your compilation error will disappear.
Originally posted by Gary Farms: When I compile the following Gary.java program, I get an error stating: Incompatible type for declaration. Can't convert java.lang.String to string. Why??? Here's my simple Gary.java program:
public class Gary { static public void main(String args[]) { string tmp = "boy"; } } Also, what class(if any) are the primitives such as integer in? Insn't everything a subclass of class Object?
Steve Lemay
Greenhorn
Joined: Apr 12, 2001
Posts: 2
posted
0
If you want to deal with primatives like objects then use the wrapper classes, you can find these in the java.lang package, there called the same as primative's but with capitilization (ie Integer). And yes all classes are ultimatley subclasses of object