Dasar Java : Access Modifier di Java – public

Oleh : Reza Ervani

بسم الله الرحمن الرحيم

Access modifier public berarti seluruh kode yang ada dapat mengakses class, field, konstruktor atau metode yang ada, tidak peduli dimanapun kode itu berada.

Berikut contohnya :

[code language=”java”]

public class Clock {
public long time = 0;
}

public class ClockReader {
Clock clock = new Clock();

public long readClock{
return clock.time;
}
}

[/code]

Class ClockReader dapat mengakses field time di Clock tidak peduli di paket apa ClockReader berada, karena baik class Clock maupun field time dideklarasikan public.

About Reza Ervani 425 Articles
Adalah pendiri programming.rezaervani.com -

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.