• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can a class be named java ?

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi everybody,
can any class be named java saved with its file name java?
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No you can't have class name as java - if you put java as a class name compiler will say something like this : java clashes with the package of the same name. Because there is a package named as java.
But your file name can be java.java but when you run you have to run the proper java class .
try out the following:
class Java{
Java(){
System.out.println("Hi!.......");
}
public static void main(String[] args){
Java Java=new Java();
}
}
this class saved in the java.java file.

to run used : java Java
-Siva
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by amit goel:
hi everybody,
can any class be named java saved with its file name java?



Hi!
I tried to compile a source file , but it did not work.I think java is a reserved word, Instead try using Java.
The error I got were:
.\java.java:1: Class java already defined in java.java.
public class java
^
error: File .\java.java does not contain nested type java. lang.Object as expect
ed. Please adjust the class path so that the file does not appear in the unnamed
package.
java.java:1: Superclass java. lang.Object of class java not found.
public class java
^
3 errors

It doesnot work it seems amit
 
reply
    Bookmark Topic Watch Topic
  • New Topic