[go: up one dir, main page]

0% found this document useful (0 votes)
67 views5 pages

(For Programming Based Labs) : Write Program To Study Access Modifiers in Java Using Packages

The document summarizes an experiment on studying access modifiers in Java using packages. It shows code examples for using default, public, private, and protected access modifiers. For default, a method can be accessed within the same package. For public, a method can be accessed anywhere. For private, a method cannot be accessed from outside its class. For protected, a method can only be accessed by subclasses in other packages. The code executed properly and demonstrated the expected behavior for each access modifier type.

Uploaded by

Navi Gill
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views5 pages

(For Programming Based Labs) : Write Program To Study Access Modifiers in Java Using Packages

The document summarizes an experiment on studying access modifiers in Java using packages. It shows code examples for using default, public, private, and protected access modifiers. For default, a method can be accessed within the same package. For public, a method can be accessed anywhere. For private, a method cannot be accessed from outside its class. For protected, a method can only be accessed by subclasses in other packages. The code executed properly and demonstrated the expected behavior for each access modifier type.

Uploaded by

Navi Gill
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

WORKSHEET EVALUATION

Experiment 1.4

Student Name: Rohan Godha UID: 20BCS1762


Branch: CSE Section/Group: CSE6-B
Semester: 3 Date of Performance: 15/09/2021
Subject Name:JAVA PROGRAMMING LAB
Subject Code: 20CSP-219

Aim/Overview of the practical:


Write program to study access modifiers in java using packages.

Task to be done/ Which logistics used:


Show the use of access modifiers i.e default ,public, private and protected.

Operating System: Windows

Algorithm/Flowchart (For programming based labs):

Software: VS Code
i. Start.
ii. Create a package.
iii. Create a class within the package.
iv. Create a method inside the class .
v. Save the code by the name of the class.java.
vi. Create another package i.e.mypack.
vii. Import all classes of package created at step 1.
viii. Create a class inside mypack package.
ix. Create main method inside this class.
x. Create object of a class of package imported at step 6.
xi. Call the method which exists inside that another class with scope defined as public.
xii. End.
Steps for experiment/practical/Code:

FOR DEFAULT
package p1;
class A
{void display()
{
System.out.println("default");
}
}
package p2;
import p1.*;
class B
{
public static void main(String args[])
{
A obj = new A();
obj.display();
}
}

FOR PUBLIC
package p1;
public class A
{public void display(){
System.out.println("sujeet kumar shah");
}
}
package p2;
import p1.*;
class B
{
public static void main(String args[])
{
A obj = new A();
obj.display();
}}
FOR PRIVATE
package p1;
class A
{
private void display()
{
System.out.println("that is private");
}
}
class B
{
public static void main(String args[])
{
A obj = new A();
//trying to access private method of another class
obj.display();

FOR PROTECTED
package p1;
public class A
{
protected void display()
{
System.out.println("sujeet");
}
}
package p2;
import p1.*;
class B extends A
{
public static void main(String args[])
{
B obj = new B();
obj.display();
}
}
Observations/Discussions/ Complexity Analysis:
The code executed properly and gave expected output.

Result/Output/Writing Summary:

DEFAULT :

PUBLIC:
PROTECTED:

PRIVATE:

Learning outcomes (What I have learnt):


1. Create a package .
2. Use of access modifiers like private , protected.

Evaluation Grid (To be created as per the SOP and Assessment guidelines by the
faculty):
Sr. No. Parameters Marks Obtained Maximum Marks
1.
2.
3.

You might also like