JAVAia
JAVAia
// File: pack2/TestPublic.java
package pack2;
import pack1.PublicExample;
// File: pack2/TestProtected.java
package pack2;
import pack1.ProtectedExample;
class DefaultExample {
void showMessage() {
System.out.println("This is a default method.");
}
}
// File: pack1/TestDefault.java
package pack1;
// File: pack1/TestPrivate.java
package pack1;
Key Points
Public: Accessible everywhere.
Protected: Accessible in the same package and through inheritance in other packages.
Default: Accessible only in the same package.
Private: Accessible only within the defining class.
These levels help in securing and encapsulating data efficiently in Java applications.
Inter-Thread Communication in Java
Inter-thread communication is a mechanism that allows synchronized threads to
communicate with each other. This is particularly useful when multiple threads need to
collaborate to complete a task. Java provides methods like wait(), notify(), and notifyAll()
in the Object class to facilitate this communication