Object Oriented Programming Language
Vadodara Institute of Engineering
Active Learning Assignment
Topic: Static Import and Access Control
Computer Engineering
Presented By:
Kashyap Patel 150800107046
Krishna Patel 150800107047
Maitree Patel 150800107048
1
Contents
 Static Import
 Access control
2
Static Import
• Static Import is a new feature added in java.
• In order to access static members, it is necessary to qualify
references with the class they came from.
• That means in order to access the static members of a class, it is
a must to write the member along with its belonging class
name.
3
Static Import
 For Example:
class A
{
Public static void main(String a[])
{
Int a=36;
Int val=Math.sqrt(a);
4
Static Import
System.out.println(“The square root of”+a”is”+val);
}
}
o/p : The square root of 36 is 6
In order to avoid unnecessary use of static class members like
Math and System, we should Static import.
5
Static Import
Import static java.lang.System.out;
Import static java.lang.Math.sqrt;
class A
{
Public static void main(String a[])
{
6
Static Import
Int a=36;
Int val=sqrt(a);
System.out.println(“the square root of”+a”is”+val);
}
}
• O/p : the square root of 36 is 6
7
Static Import
• Note that ambiguous static import is not allowed.
• That means two different classes referencing the same
functionality is not allowed.
Advantage:
• The advantage of using static import is that readability of the
code increases as it avoids writing of belonging class name
each time. 8
Access control
• Access specifiers: visibility modifiers.
– Private
– default
– protected
– public
• these specifiers specify the scope .
9
Access control
• Private members can be accessed within the class where they
are declared. They are not allowed outside the class.
• Top level classes can be default and public but not private
• we can use these 4 specifies for all the members of the class
• these specifiers are not allowed for local variables
10
Access control
Class A
{
private int a;
Void set_a(int i)
{
A=I; }}
Declared
private
11
Access control
class B extends A
{ int b;
Void set_b(int i)
{ B=i; }
Void mul()
{ Int c;
12
Access control
C=a*b;
System.out.println(“mul is”+c);}}
class xyz
{
Public static void main(String a[])
{
13
Access control
A a=new A;
B b=new B;
b.set_a(10);
b.set_b(4);
b.mul();
} }
14
References
• https://www.tutorialspoint.com/java/java_access_modifiers.htm
• https://www.javatpoint.com/static-import-in-java
15
Thank You
16

Static Import and access modifiers