-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodifierExample.java
More file actions
25 lines (23 loc) · 997 Bytes
/
modifierExample.java
File metadata and controls
25 lines (23 loc) · 997 Bytes
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
package accessModifier;
import modifiers.custompack;
public class modifierExample extends custompack {
public static void main(String[] args) {
custompack cp = new custompack();
modifierExample me = new modifierExample();
// sayhello(); // default method[sayhello()] -- cannot be accessed outside the
// package directly with the same class object or inheritance
// public method[welcome()] -- can be accessed anywhere either by same class
// object or by child class object after inheritance.
cp.welcome();
me.welcome();
// protected method [createdby()] -- can only be accessed by the object of child
// class after inheritance.
me.createdby();
// private method [thankyou()] -- cannot be accessed outside the class directly.
// can only be accessed outised from a public method of the same class.
// default methods can also be accessed outside the package if called from the
// public method of the same class.
me.accessprivate();
cp.accessprivate();
}
}