Four types of modifiers
1. public - any class can access your class
2. package private or no modifiers - a class that belongs to the same package can access your class.
3. protected - a class that belongs to the same package and a subclass from a different package can access your class.
4. private - accessible only within the class itself.
class - class has two modifiers, a public and a package private.
==================================
Example:
public class Example1{} // public modifier
class Example2{} // package private or no modifier
====================================
members - when talking about members, these are the constructors, fields and methods inside the class. Members has four modifiers.
==============================
Example:
class Example3{
private String name;
public Example3(String name){
this.name = name;
}
void myMethod1(){
System.out.println("I am a package private member!");
}
protected myMethod2(){
System.out.println("I am a protected member!");
}
}
================================
YOU ARE READING
Java Programming
Randomhttps://docs.oracle.com/javase/tutorial/ This is the link where I learned my java lessons online. I choose java as first programming language. I am a career shifter. I just want to start something new. I choose to write it here in Wattpad so that I...