Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Help Java A Java Abstract Class

Related Tutorials


 
 

Share on Google+Share on Google+

Java Abstract Class

Advertisement
An abstract class is a class that is declared by using the abstract keyword.

Java Abstract Class

     

An abstract class is a class that is declared by using the abstract keyword. It may or may not have abstract methods. Abstract classes cannot be instantiated, but they can be extended into sub-classes.

        --or--

Java provides a special type of class called an abstract class. Which helps us to organize our classes based on common methods. An abstract class lets you put the common method names in one abstract class without having to write the actual implementation code.

An abstract class can be extended into sub-classes, these sub-classes usually provide implementations for all of the abstract methods.

The key idea with an abstract class is useful when there is common functionality that's  like to implement in a superclass and some behavior is unique to specific classes. So you implement the superclass as an abstract class and define methods that have common subclasses. Then you implement each subclass by extending the abstract class and add the methods unique to the class.
 
Points of abstract class :

  1. Abstract class contains abstract methods.
  2. Program can't instantiate an abstract class.
  3. Abstract classes contain mixture of non-abstract and abstract methods.
  4. If any class contains abstract methods then it must implements all the abstract methods of the abstract class.
Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 27, 2009

Related Tutorials

Discuss: Java Abstract Class   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:14
mahes
February 3, 2012
help me

i need exact example for abstract....... and i have one doubt abstract class, abstract methods can be accessible in subclasses or not.
Ibrar Hussain
May 25, 2012
Java

I much like to learn java subject.
shalz
June 26, 2012
abstract class versus interface

just help me how can i differ abstract class & interface????for me both looks same:-(
SONU SINGH
July 24, 2012
java

please sir send me some java defination,methods,or any containts
Saqib Afridi
September 16, 2012
BS(IT)

I understand this very much because this is very simple so, every one can understand very much. I will try to get more and more knowledge from this site.
gagan
September 30, 2012
java

why we use abstract class in java?
Prasad
November 22, 2012
Abstract class and abstract method

Can you explain abstract class and method with example.....
fridoon
January 2, 2013
Abstract class

i am a website developer .. What is the use of abstract class and when its used?
Nurul Fazdreen Binti Saifuzzaman
September 25, 2013
object oriented programming

im need help u., Write a java program with following features: 1. Have one abstract class name Kereta 2. Abstract class kereta have following data member: a. protected double hargaKereta; b. protected double cukai; c. protected double hargaOnTheRoad; d. protected String inputNama; 3. Abstract class have following method a. Abstract method name KiraCukai() b. Method Input() to input name of a car and its price.(This method are given below) 4. Class Proton inherit from class Kereta with implementation of KiraCukai(). This method will calculate tax base on 10% sales tax and 5% eksesais tax. This method will print car price on the road together with its name. 5. Class Honda inherit from class Kereta with implementation of KiraCukai(). This method will calculate tax base on 50% sales tax and 10% eksesais tax. This method will print car price on the road together with its name. 6. Class TestKereta will create object BLM from class Proton and object Civic from class Honda. This two object will call all method they have. Method Input(): void Input()throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String inputHarga; System.out.println("Masukkan Nama Jenama Kereta: "); inputNama=br.readLine(); System.out.println("Masukkan Harga Kereta: "); inputHarga=br.readLine(); hargaKereta=Double.parseDouble(inputHarga); } Example Output: Masukkan Nama Jenama Kereta: Proton BLM Masukkan Harga Kereta: 45000 Cukai: 6750.0 Harga Proton BLM Atas Jalan: RM51750.0 Masukkan Nama Jenama Kereta:Honda CRV Masukkan Harga Kereta: 100000 Cukai: 60000.0 Harga Honda CRV Atas Jalan: RM160000.0
DMCA.com