Core Java Articles


Total available count: 12
Subject - Java Technologies
Subsubject - Core Java

Key points about Abstract Class

If class is declared with modifier as abstract then object creation is not possible. If a class contains at least one or more abstract methods or all normal methods with modifier abstract before class is called abstract class. Main difference between normal class and abstract class is object creation is not possible with abstract class.
It is possible to Declare main method inside the abstract class, because we are not creating any object.

Let us see an example about main method inside the abstract class:

abstract class Slightbook
{
	public static void main(String[] args)
	{
		System.out.println("The main method inside the abstract class");
	}
}

 

Output:

The main method inside the abstract class

It is also possible to declare and execute the Constructor in the abstract class just like as it possible to declare and execute variables, methods, Instance and static blocks.

Let us see another example regarding this:

abstract class Parent
{
	Parent()
{
System.out.println("In the parent class constructor");
}
	{System.out.println("In the parent class Instance block");}
	static{System.out.println("In the parent class static block");}
}
class Child extends Parent
{
	 Child()
	{
		 super();      //this will call parent zero arguments constructor
		 System.out.println("In the Child class constructor");
	}
	{System.out.println("In the Child class Instance block method");}    //optional
	static{System.out.println("In the Child class static block method");}  //optional
	public static void main(String[] args)
	{
		Child c = new Child();
	}
}

 

Output:

In the parent class static block
In the Child class static block method
In the parent class Instance block
In the parent class constructor
In the Child class Instance block method
In the Child class constructor

Let us see the main difference between abstract class, interface, and class.

  1. A class contains all declarations and implementations
  2. An interface contains declarations only but not implementations
  3. An abstract class contains some declarations and some implementations
Class <name>
{ 
	.All declarations;
	.All implementations;
}

Interface <name>
{
	..only declarations;
}

Abstract class <name>
{
	...Some declarations;
	...Some implementations;
}

 

Abstraction is the process of highlighting services and hiding its implementation is called abstraction.




Next 5 article(s)

1
Polymorphism and types of polymorphism
2
Rules to be followed for Overriding Concept
3
Strings in Java
4
About Instance Block
5
About String and StringBuffer classes with Examples

Comments