Reading:  

Quick introduction to Object oriented concepts in Java - Part 2 of series


What is Abstraction?

Abstraction is process to hide implementation details and only show essential features of object.

Abstraction in java is achieved through interface and abstract class. Interface provides 100% abstraction and abstract class provides 0-100% abstraction.

Abstract Class

A class which is declared as abstract is known as abstract class.

Syntax:

abstract class <class-name>{}

An abstract class is an incomplete class and we cannot create instance. By extending it can be made complete or concrete.

A class is concrete if it does not contain any abstract method and implements all abstract method inherited from interface or abstract class it extended or implemented.

Abstract Method

Aabstract method has declaration without any implementation. If the method is abstract then the class also must be abstract.

Syntax:

Abstract return_type method_name ();

The abstract method needs to overridden in subclass in order to use it.

abstract class vehical {
	abstract void checkSpeed();
}

class Car extends Vehical {
	void checkSpeed() {
		System.out.println("Speed is 60");
	}

	public static void main(String args[]) {
		vehicalobj = new Car();
		obj.checkSpeed(); //Prints Speed is 60
	}
}

 

Abstract Class vs. Interface

Java provides and supports the creation of interfaces and abstract classes. Some of the differing features:

  • All methods in interface are implicitly abstract. While abstract class may contain both non-abstract and abstract methods.
  • A class may implement more than one Interface, but can extend only one abstract class.
  • Abstract classes can implement interfaces without providing implementation of interface methods.
  • Variables declared in Java interface are final default.
  • Members of Java interface are always public. A member of abstract class can either be protected, private or public.

Description

This tutorial will introduce you to Object oriented concepts in Java. Basic definitions and learning with code examples.

This tutorial has subdivided into 7 parts as listed below

  1. Understanding Inheritance    
  2. Understanding Overrides
  3. Understanding Polymorphism
  4. Understanding Abstraction
  5. Understanding Encapsulation
  6. Understanding Interfaces
  7. Understanding Packages

Let us know if you found any error in this tutorial. Your feedback is welcome as always.



Audience

Students seeking a quick overview on Java Programming language and its Object oriented features.

Learning Objectives

Learn Object Oriented concepts in Java language.

Author: Subject Coach
Added on: 10th Mar 2015

You must be logged in as Student to ask a Question.

None just yet!