Synchronization is a technique to have control over threads over a shared resources. If they are not managed properly they would give wrong answer. This is race condition.

Synchronization in java can be achieved using.
1. Extending Thread class.
2. Implementing Runnable interface.

Types:
1. Process synchronization
2. Thread synchronization

Thread Synchronization:

How we achieve synchronization:
1. By Using Synchronized Method
2. By Using Synchronized Block
3. By Using Static Synchronization

Without synchronizing method:

--

--

Sometimes unexpected errors can occur while overloading methods . These errors involve ambiguity because both the methods are valid candidates for invocation. The compiler cannot make decision on which method to bind the method call.

--

--

  1. Field, methods, classes in java can be final.
  2. Final keyword prevents the variable, method, class from being override/Modified.
  3. When class is final => subclass of it cannot be created.
    When variable is final => its value cannot be changed.
    When method is final => it cannot be overriden.

Final variable:

Output: 20
Once final variable is assigned later it can’t be assigned if you try it will give error as variable i might already have been assigned

The same applies for methods and classes too it final method ,class are overrided or inherited it throws an error.

--

--