• 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

!!!MOST UNBELIVEABLE!!!

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear frns,
examine the code below carefully and just tell wethet it will compile.

yes the code above will compile !!Zapped !!!
YES A FULLY EMPTY FILE IS A VALID SOURCE FILE AND COMPILES WITHOUT ANY ERROR
can any one give me a logical explanation?
also
A Java file without any class or interface definitions can also be compiled.
AMIT
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Amit,
See whether you get any class file when you compile an empty file. You don't get any. That means there is nothing to compile. To answer your second part, in Java, everything has to be in a class. You can not have free standing methods or variables as in C. If you have some variable or method not inside any class, then compiler issues this error message:
Class or interface declaration expected
Ramesh.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Amit:
The Java Language Specification basically says that a Java
source file consists of the following 3 parts:
1. An OPTIONAL package statement
2. ZERO or more import statements
3. ZERO or more class definitions
Therefore, there's nothing stopping you from compiling
successfully an empty source file (of course, it's absolutely
useless -- but that's another matter entirely).
Hope that helps.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic