• Post Reply Bookmark Topic Watch Topic
  • New Topic

importing package  RSS feed

 
MaheshS Kumbhar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do have file Myclass.class inside package A.B
then what are the meaning of following three statement used individually.

import A.B.MyClass;
import A.B.*;
import A.B.MyClass.*;

 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MaheshS Kumbhar wrote:I do have file Myclass.class inside package A.B
then what are the meaning of following three statement used individually.

import A.B.MyClass;
import A.B.*;
import A.B.MyClass.*;


Ok given you have the following file structure

The first 2 imports are correct given your description by importing only MyClass.java file and importing all java files in the B directory (the asterisk). The third import means you are importing files in the MyClass directory (blabla.java file)
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not necessarily. You are right about the first 2 imports, but the third import will also import any nested classes / interfaces of class A.B.MyClass. These nested classes can be both static and non-static. For instance: import java.util.Map.* will allow you to write Entry instead of Map.Entry.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!