-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ6(EP).java
More file actions
57 lines (43 loc) · 1.16 KB
/
Q6(EP).java
File metadata and controls
57 lines (43 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
1. Write a program to show the difference between public, private access specifier
the programme should also show that primitive data types are passed by value and objects are passed by reference.
// Java program to showcase the example
// of public access modifier
// import required packages
import java.io.*;
import java.util.*;
// declaring a public class
public class A {
// declaring method m1
public void m1() { System.out.println("GFG"); }
}
class B {
// main method
public static void main(String[] args)
{
// creating an object of type class A
A a = new A();
// accessing the method m1()
a.m1();
}
}
// Java program to showcase the example
// of private access modifier
// import required packages
import java.io.*;
import java.util.*;
// helper class
class A {
// helper method
private void m1() { System.out.println("GFG"); }
}
// driver class
class B {
// main method
public static void main(String[] args)
{
// creating an object of type class A
A a = new A();
// accessing the method m1()
a.m1();
}
}