All about final abstract class and final class
Abstract And Final Class

Abstract class

  • A partially implemented and partially unimplemented class, is called as abstract class.
  • Definition : A class which have at least one abstract method, is called as abstract class explicitly.
  • Keyword abstract is used to declare this class explicitly, Abstract class cannot be instantiated because it may have abstract method.

Write a program to define abstract class execution.
abstract class Abs1
{
 public void fun1()
 {
  System.out.println("Hello abstract class method");
 }
 abstract public void fun2();
}

class Abs extends Abs1
{
 public void fun2()
 {
  System.out.println("Hello fun2 sub class method");
 }
 
 public static void main(String args[])
 {
  Abs a1 = new Abs();
   a1.fun1();
   a1.fun2();
  Abs1 a2 = new Abs();
   a1.fun1();
   a1.fun2();
 }
}



Abstract class can created in 3 ways:
1) Declare abstract method in class.
2) Declare keyword 'abstract' with class.
3) Do not implement the interface completely.

Final class:

  • A class which can Inherit others but cannot be inherited by other is called final class.
  • Keyword "final" is used to declare final class explicitly.
  • final class is the last class of inheritance chain.
Write a program implement final class execution.
final class fin extends object
{
 public void fun1()
 {
  System.out.println("Hello final class method");
 }
}
class fun1
{
 public void fun2()
 {
  System.out.println("Hello sub class method");
 }
 public static void main(String args[])
 {
  fin1 f1=new fin1();
  //f1.fun1();
  f1.fun2();
  fun f2=new fun();
  f2.fun();
 }
}


Difference between abstract and final class.
1) Abstract class cannot be instantiated.
2) Abstract class should be inherited in some other class.
3) Abstract class may have abstract methods.
4) Super class reference and sub class object concept is followed by abstract.
5) Abstract keyword is used to declare this class
1) The object creation process of final class is compulsory.
2) final class cannot be inherited.
3) final class doesnot have abstract method.
4) this concept is not followed by final class.

5) final keyword is used to declare this class.


Note : The class can be either abstract or final.


abstract
final
static
  • class
  • variables
  • methods
  • constructor
Axact

Narendra

Hello, everyone! I am Narendra Bagul founder of Javanotes9. First of all thank you for visiting my blog. Hope you all like my java notes as well. I'm young part time blogger and a Computer Engineering student. I started blogging as a hobby. Now here I'm sharing my little acquired knowledge about my favorite programming language JAVA.

Post A Comment: