G
grocery_stocker
In the following:
public class toupper {
private static void upper(){
String a = "chad";
System.out.println("Upper Case is:" + a.toUpperCase());
}
public static void main (String[] args) {
upper();
}
}
Why isn't the line
String a = new String();
Necessary? I thought this line might be omitted because for whatever
reasons I was thinking toUpperCase() was a static method. It isn't.
Because when I change the line:
System.out.println("Upper Case is:" + a.toUpperCase());
to
System.out.println("Upper Case is:" + String.toUpperCase());
I get the following:
$javac toupper.java
toupper.java:6: non-static method toUpperCase() cannot be referenced
from a static context
System.out.println("Upper Case is:" + String.toUpperCase());
^
1 error
public class toupper {
private static void upper(){
String a = "chad";
System.out.println("Upper Case is:" + a.toUpperCase());
}
public static void main (String[] args) {
upper();
}
}
Why isn't the line
String a = new String();
Necessary? I thought this line might be omitted because for whatever
reasons I was thinking toUpperCase() was a static method. It isn't.
Because when I change the line:
System.out.println("Upper Case is:" + a.toUpperCase());
to
System.out.println("Upper Case is:" + String.toUpperCase());
I get the following:
$javac toupper.java
toupper.java:6: non-static method toUpperCase() cannot be referenced
from a static context
System.out.println("Upper Case is:" + String.toUpperCase());
^
1 error