Importing package and sub packages in JAVA

Asked By 0 points N/A Posted on -
qa-featured

Does importing package and sub package in JAVA the same? For instance, when we try to import com.MyTest, is it the same as importing com.MyTest.UnitTests?

SHARE
Answered By 0 points N/A #94005

Importing package and sub packages in JAVA

qa-featured

1)Using import com.MyTest

Importing packages and sub packages is absolutely not the same. Considering you example, if we import com.MyTest i.e. we are importing the 'MyTest' class in the 'com' package then we can directly use all the items which are stated as public in MyTest class.

But to use the public items in 'UnitTests' class(subclass of 'MyTest' class) using the above import statement we have to use the dot(.) operator. For eg, UnitTests.item1()

2)Using importcom.MyTest.UnitTests

Here we can directly access all the public members of UnitTests class. But there is no way through which we can directly access any items from MyTest class. 

Related Questions