• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Missing import statment

 
garima jain
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • 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.
 
Ankit Garg
Sheriff
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
thanks Ankit
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • 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: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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...
 
Pandey Gautam
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic