OCA7
IT is a compiler error if you import classes from default package
OCA7
OCA7
gurpeet singh wrote:yes you are right. for classes in same package(in your case since they both are in same but default package) they need not use any import statement or fully qualified class name to access class in the same package. we use import statement to import classes in other package .
ankita modi. wrote:You're right Mr. Gurpreet, there is a compile error.
Henry Wong wrote:
gurpeet singh wrote:yes you are right. for classes in same package(in your case since they both are in same but default package) they need not use any import statement or fully qualified class name to access class in the same package. we use import statement to import classes in other package .
ankita modi. wrote:You're right Mr. Gurpreet, there is a compile error.
Gurpeet said that classes in the default package can call each other without using import. How is that statement wrong? ... having an incorrect classpath doesn't change that statement.
Henry
OCA7
gurpeet singh wrote:first of all there is no such thing as auto-import.
For convenience, the Java compiler automatically imports three entire packages for each source file: (1) the package with no name, (2) the java.lang package, and (3) the current package (the package for the current file).
OCA7
ankita modi. wrote:
For convenience, the Java compiler automatically imports three entire packages for each source file: (1) the package with no name, (2) the java.lang package, and (3) the current package (the package for the current file).
SOURCE:javatutorials/java/package/usepkgs.html
Each compilation unit automatically imports all of the public type names declared in the predefined package java.lang, as if the declaration:appeared at the beginning of each compilation unit, immediately following any package statement.
A compilation unit automatically has access to all types declared in its package and also automatically imports all of the public types declared in the predefined package java.lang.
luck, db
There are no new questions, but there may be new answers.
OCA7
ankita modi. wrote:No,that is correct information.SOURCE:http://docs.oracle.com/javase/tutorial/java/package/usepkgs.html
Although it is true that noname package classes can be access only within same package.
luck, db
There are no new questions, but there may be new answers.
Each compilation unit automatically imports all of the public type names declared in the predefined package java.lang, as if the declaration:appeared at the beginning of each compilation unit, immediately following any package statement.
A compilation unit automatically has access to all types declared in its package and also automatically imports all of the public types declared in the predefined package java.lang.
OCA7
ankita modi. wrote:I am not getting difference here.Could you elaborate it ?
ankita modi. wrote:
For convenience, the Java compiler automatically imports three entire packages for each source file: (1) the package with no name, (2) the java.lang package, and (3) the current package (the package for the current file).
SOURCE:javatutorials/java/package/usepkgs.html
ankita modi. wrote:
From The Java Language Specification, Third EditionEach compilation unit automatically imports all of the public type names declared in the predefined package java.lang, as if the declaration:appeared at the beginning of each compilation unit, immediately following any package statement.
In The Java™ Language Specification, Java SE 7 Edition this information can be found in a different section.A compilation unit automatically has access to all types declared in its package and also automatically imports all of the public types declared in the predefined package java.lang.
Ivan Jozsef Balazs wrote:>java p.b
class a
Henry Wong wrote:Care to show us how you would access a field or call a method -- as it is pretty annoying to do with reflection.
Your mind is under my control .... your will is now mine .... read this tiny ad
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|