JAVA Lecture 10
JAVA Lecture 10
Final Keyword:-
The final keyword in java is used to restrict the user. When a final keyword is it says that that particular
entity is unchangeable. Java final keyword can be used in different ways:-
• Java Final variable.
• Java Final method.
• Java Final class.
final int a =10; // means now the value to variable will 10 we cannot change it.
• Java Final method:-
When we declare final keyword with a method in java the method here cannot be overridden, i.e we
cannot cannot override a final method and it body cannot be changed.
Syntax:-
public final void test(){
Syntax :-
final class demo(){
}
Interface :-
Like a class, an interface can have methods and variables, but the methods declared in an interface are by
default abstract (only method signature, no body).
Interface is one of the Oops principle, interface is 100%
abstract(incomplete) in nature i.e. all the methods inside the interface is incomplete. Interface is also called as blueprint of a
class as we only declare methods and use them later as required.
Key Points:-
• No Constructor are present inside an interface.
• Interface members are by default public.
• No need to use abstract keyword while declaring an interface.
• Variable declared in interface are always public, static and final.
• With help of interface, we can perform multiple inheritance in java.
• Methods declared inside an interface are by default public and Abstract.
• An interface is implemented by using implements Keyword.
• The class which completes the methods of an interface is called as implementation class.
• Note:- post java 8 we can write complete method in interface but that method will be always static method.