Presentation is loading. Please wait.

Presentation is loading. Please wait.

Modifier in Java Modifier in java Modifier in Java *Suatu akses ke classes, constructors, methods, dan fields. Dapat mengkontrol informasi yang dapat.

Similar presentations


Presentation on theme: "Modifier in Java Modifier in java Modifier in Java *Suatu akses ke classes, constructors, methods, dan fields. Dapat mengkontrol informasi yang dapat."— Presentation transcript:

1

2 Modifier in Java

3 Modifier in java

4 Modifier in Java *Suatu akses ke classes, constructors, methods, dan fields. Dapat mengkontrol informasi yang dapat diakses oleh class lain. *Suatu akses ke classes, constructors, methods, dan fields. Dapat mengkontrol informasi yang dapat diakses oleh class lain.

5 Modifier in java: in same package

6 BaseClass SubclassInSamePackage Extends

7 SamePackage:1 package pckage1; class BaseClass { public int x = 10; private int y = 10; protected int z = 10; int a = 10; //Implicit Default Access Modifier package pckage1; class BaseClass { public int x = 10; private int y = 10; protected int z = 10; int a = 10; //Implicit Default Access Modifier public class SubclassInSamePackage extends BaseClass { public static void main(String args[]) { BaseClass rr = new BaseClass(); rr.z = 0; SubclassInSamePackage subClassObj = new SubclassInSamePackage();

8 SamePackage:2 package pckage1; class BaseClass { public int x = 10; private int y = 10; protected int z = 10; int a = 10; package pckage1; class BaseClass { public int x = 10; private int y = 10; protected int z = 10; int a = 10; System.out.println("Value of x is : " + subClassObj.x); subClassObj.setX(20); System.out.println("Value of x is : " + subClassObj.x); // System.out.println("Value of y is : "+subClassObj.y); //subClassObj.setY(20); *Private System.out.println("Value of z is : " + subClassObj.z); subClassObj.setZ(30); System.out.println("Value of z is : " + subClassObj.z); System.out.println("Value of x is : " + subClassObj.a); subClassObj.setA(20); System.out.println("Value of x is : " + subClassObj.a); System.out.println("Value of x is : " + subClassObj.x); subClassObj.setX(20); System.out.println("Value of x is : " + subClassObj.x); // System.out.println("Value of y is : "+subClassObj.y); //subClassObj.setY(20); *Private System.out.println("Value of z is : " + subClassObj.z); subClassObj.setZ(30); System.out.println("Value of z is : " + subClassObj.z); System.out.println("Value of x is : " + subClassObj.a); subClassObj.setA(20); System.out.println("Value of x is : " + subClassObj.a); Value of x is :10 Value of x is : 20 Value of x is :10 Value of x is : 20

9 SubclassDifferent Package

10 SubclassDifferent Package:1 BaseClass SubclassInSamePackage Extends SubClassInDifferentPackage Extends

11 import pckage1.*; public class SubClassInDifferentPackage extends SubclassInSamePackage { public static void main(String args[]) { SubClassInDifferentPackage subClassDiffObj = new SubClassInDifferentPackage(); SubclassInSamePackage subClassObj = new SubclassInSamePackage(); import pckage1.*; public class SubClassInDifferentPackage extends SubclassInSamePackage { public static void main(String args[]) { SubClassInDifferentPackage subClassDiffObj = new SubClassInDifferentPackage(); SubclassInSamePackage subClassObj = new SubclassInSamePackage(); SubClassDifferent Package:2 public class SubclassInSamePackage extends BaseClass { public static void main(String args[]) { BaseClass rr = new BaseClass(); rr.z = 0; SubclassInSamePackage subClassObj = new SubclassInSamePackage();

12 System.out.println("Value of x is : " + subClassObj.x); subClassObj.setX(30); System.out.println("Value of x is : " + subClassObj.x); /* System.out.println("Value of y is : "+subClassObj.y); subClassObj.setY(20); System.out.println("Value of y is : "+subClassObj.y);*/ /* System.out.println("Value of z is : "+subClassObj.z); subClassObj.setZ(30); System.out.println("Value of z is : "+subClassObj.z);*/ System.out.println("Value of z is : " + subClassDiffObj.getZZZ()); /* System.out.println("Value of a is : "+subClassObj.a); subClassObj.setA(20); System.out.println("Value of a is : "+subClassObj.a);*/ System.out.println("Value of x is : " + subClassObj.x); subClassObj.setX(30); System.out.println("Value of x is : " + subClassObj.x); /* System.out.println("Value of y is : "+subClassObj.y); subClassObj.setY(20); System.out.println("Value of y is : "+subClassObj.y);*/ /* System.out.println("Value of z is : "+subClassObj.z); subClassObj.setZ(30); System.out.println("Value of z is : "+subClassObj.z);*/ System.out.println("Value of z is : " + subClassDiffObj.getZZZ()); /* System.out.println("Value of a is : "+subClassObj.a); subClassObj.setA(20); System.out.println("Value of a is : "+subClassObj.a);*/ package pckage1; class BaseClass { public int x = 10; private int y = 10; protected int z = 10; int a = 10; //Implicit Default Access Modifier package pckage1; class BaseClass { public int x = 10; private int y = 10; protected int z = 10; int a = 10; //Implicit Default Access Modifier SubClassDifferent Package:3

13 DifferentPackage

14 BaseClass SubclassInSamePackage Extends SubClassInDifferentPackage Extends classDifferentPackage

15 DifferentPackage:2 import pckage1.*; public class ClassInDifferentPackage { public static void main(String args[]) { SubclassInSamePackage subClassObj = new SubclassInSamePackage(); System.out.println("Value of x is : " + subClassObj.x); subClassObj.setX(30); System.out.println("Value of x is : " + subClassObj.x); /* System.out.println("Value of y is : "+subClassObj.y); subClassObj.setY(20); System.out.println("Value of y is : "+subClassObj.y);*/ /* System.out.println("Value of z is : "+subClassObj.z); subClassObj.setZ(30); System.out.println("Value of z is : "+subClassObj.z);*/ /* System.out.println("Value of a is : "+subClassObj.a); subClassObj.setA(20); System.out.println("Value of a is : "+subClassObj.a);*/ import pckage1.*; public class ClassInDifferentPackage { public static void main(String args[]) { SubclassInSamePackage subClassObj = new SubclassInSamePackage(); System.out.println("Value of x is : " + subClassObj.x); subClassObj.setX(30); System.out.println("Value of x is : " + subClassObj.x); /* System.out.println("Value of y is : "+subClassObj.y); subClassObj.setY(20); System.out.println("Value of y is : "+subClassObj.y);*/ /* System.out.println("Value of z is : "+subClassObj.z); subClassObj.setZ(30); System.out.println("Value of z is : "+subClassObj.z);*/ /* System.out.println("Value of a is : "+subClassObj.a); subClassObj.setA(20); System.out.println("Value of a is : "+subClassObj.a);*/ package pckage1; class BaseClass { public int x = 10; private int y = 10; protected int z = 10; int a = 10; //Implicit Default Access Modifier package pckage1; class BaseClass { public int x = 10; private int y = 10; protected int z = 10; int a = 10; //Implicit Default Access Modifier


Download ppt "Modifier in Java Modifier in java Modifier in Java *Suatu akses ke classes, constructors, methods, dan fields. Dapat mengkontrol informasi yang dapat."

Similar presentations


Ads by Google