• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Missing import statment

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Source: Whizlabs


What is the result of compiling and running this code assuming that the file bb.txt does not exist.
I thought the answer to this question would be Compilation error as import statement is missing and there is no numbering given on the left hand side. However, Whizlabs does not say this.
Please suggest. Thanks.
 
Sheriff
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The real exam codes will always have line numbers. And if the line numbers don't start with 1, then you don't have to worry about import statements...
 
garima jain
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Ankit
 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if i wont find import statement or line-1

then can i put answer as compilation fails...?
 
Ankit Garg
Sheriff
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the line numbers are not beginning from 1, then you can assume that all the required import statements are there. But if the line numbers start from 1, then you cannot assume that there are required import statements. So if the line number start from 5, and there is use of File class, then you can assume that there is an import java.io.*; statement on the lines not shown. But if the line numbers start from 1, and there is no import java.io.* or java.io.File, and the code uses the File class, then it would be a compilation error...
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ankit,
I read somewhere that import.lang is implicit import for any java file.
Is it correct?
 
Ankit Garg
Sheriff
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes. You can use classes in java.lang package without importing any package. Like the Object and System classes are in the java.lang package along with the wrapper classes, String class and a lot of other classes which you can use directly...
 
Eat that pie! EAT IT! Now read this tiny ad. READ IT!
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic