0% found this document useful (0 votes)
2 views

JAVA Lecture 10

The document explains the use of the final keyword in Java, which restricts changes to variables, methods, and classes. It details how final variables cannot be reassigned, final methods cannot be overridden, and final classes cannot be inherited. Additionally, it describes interfaces in Java, highlighting their abstract nature, the absence of constructors, and their role in enabling multiple inheritance.

Uploaded by

akashsable0571
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

JAVA Lecture 10

The document explains the use of the final keyword in Java, which restricts changes to variables, methods, and classes. It details how final variables cannot be reassigned, final methods cannot be overridden, and final classes cannot be inherited. Additionally, it describes interfaces in Java, highlighting their abstract nature, the absence of constructors, and their role in enabling multiple inheritance.

Uploaded by

akashsable0571
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Java Basics

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.

• Java Final Variable:-


When a final keyword is used with a variable it is said that the variable has a final value, i.e we
cannot change the value of the variable, new value cannot be assigned to a variable.
Syntax :-

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(){

• Java Final class :-


When we declare the final keyword with the declaration class the class is known as final class,
We cannot inherit a final class.

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.

You might also like