Lecture-1.1.3
Lecture-1.1.3
Lecture-1.1.3
DEPARTMENT : CSE
Bachelor of Engineering (Computer Science & Engineering)
PROJECT BASED LEARNING IN JAVA WITH LAB
(21CSH-319/21ITH-319)
TOPIC OF PRESENTATION:
3. A class can have only one package declaration but it can have more than
one package import statements. For example:
package abcpackage; //This should be one
import xyzpackage;
import anotherpackage;
import anything;
4. The wild card import like package.* should be used carefully when working with subpackages.
For example: Lets say: we have a package abc and inside that package we have another
package foo, now foo is a subpackage.
classes inside abc are: Example1, Example 2, Example 3
classes inside foo are: Demo1, Demo2
So if I import the package abc using wildcard like this:
import abc.*;
Then it will only import classes Example1, Example2 and Example3 but it will not import the
classes of sub package.
To import the classes of subpackage you need to import like this:
import abc.foo.*;
This will import Demo1 and Demo2 but it will not import the Example1, Example2 and Example3.
So to import all the classes present in package and subpackage, we need to use two import
statements like this:
import abc.*;
import abc.foo.*;
Java Access Modifiers – Public, Private, Protected & Default
An access modifier restricts the access of a class, constructor, data member and
method in another class. In java we have four access modifiers:
1. default
2. private
3. protected
4. public
1. Default access modifier
When we do not mention any access modifier, it is called default access modifier. The
scope of this modifier is limited to the package only.
This means that if we have a class with the default access modifier in a package, only
those classes that are in this package can access this class. No other class outside
this package can access this class.
Similarly, if we have a default method or data member in a class, it would not be visible in
the class of another package.
Video Lectures :
https://www.youtube.com/watch?v=eEujVn-ZTLE
Reference Links:
https://www.geeksforgeeks.org/packages-in-java/
https://www.javatpoint.com/package
THANK YOU