0% found this document useful (0 votes)
21 views4 pages

Java Final, Abstract, Static Guide

Hall kn gghhhjbbvbhhjnjj jiiikkkkkk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

Java Final, Abstract, Static Guide

Hall kn gghhhjbbvbhhjnjj jiiikkkkkk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Final – Final is a modifier which provides

restriction.
- In java we can use final in three ways : -
Variable, method, class.
- Final variable – Once we declare a variable as
final we cannot perform re-assignment.
- In java final variable is written in uppercase.
Syntax – final int A = 10;
- Whenever we declare a method as final it
cannot be overridden to our extended class.
Syntax – final void show()
{
//code
}
- Final class – Whenever we declare a class as a
final it cannot be extended or inherited to sub
classes.
Syntax – final class A{
//code
}
Abstract - The abstract keyword in Java is used
to define classes and methods that cannot be
instantiated directly or must be implemented
by subclasses.
- An abstract class is a class that cannot be
instantiated directly. Instead, it is meant to be
extended by other classes, which can provide
concrete implementations of its abstract
methods.
- An abstract method is a method that does not
have an implementation. It is declared using the
abstract keyword and ends with a semicolon
instead of a method body.
Syntax - Syntax:-
abstract class Employee
{
abstract void work();
}
- We cannot declare abstract methods in non
abstract class.
Ex- abstract class Vehicle
{
abstract void bike();
}
class Honda extends Vehicle
{

@Override
void bike() {
[Link]("Bike is running");

public class AbstractExample1 {

public static void main(String[] args) {

Honda obj=new Honda();


[Link]();
}
}

Static – It is a non access modifier.


- The static keyword in Java is used for memory
management mainly.
- We can apply static keyword with variables,
methods, blocks and nested classes.
- We can use only with class level variable not
local variable.
- Static variable belongs to the class not object(it
means we don’t need to create an object).
- Static keyword belongs to class , not object.
- Static method can be called directly by class
name or without class name.
Syntax – [Link]()

You might also like