Wednesday, December 31, 2014

Java Tutorial For Beginners 23 - Public, Private, Protected and this (Ja...











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
package lesson1;
/*Access Levels
Modifier Class Package Subclass World
public          Y      Y  Y           Y
protected   Y     Y         Y               N
no modifier   Y      Y   N           N
private           Y  N   N           N
*/
public class Student {
 private String name;
 private int age;
 
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public int getAge() {
  return age;
 }
 public void setAge(int age) {
  this.age = age;
 }

}



public class MyClass {

 public static void main(String[] args) {
  Student stu = new Student();
  stu.setName("mark");
  System.out.println(stu.getName());
 }
    
}












package protected java

java package visibility

java protected visibility

java class visibility

java default public private

java method visibility

java default protected

java protected vs default

java access modifiers example

java access modifiers inheritance

java non access modifiers

java final

java access modifiers for class

java access modifiers matrix

java access modifiers package-private

java access modifiers


No comments:

Post a Comment