• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

abstarct class

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can an abstract class extend concrete class?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes an abstract class can extends concrete class.
Example:
Concrete .java
public class Concrete
{
public void add(){
int i = 3;
int j = 5;
int z = i+j;
System.out.println("Sum is:"+z);

}
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}

Extended .java
public abstract class Extended extends Concrete
{
public static void main(String[] args)
{
Concrete c = new Concrete();
c.add();

}
}

Output is: Sum is:8
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by abhinava srivastava:
can an abstract class extend concrete class?



Basically What does an abstract class mean?
It is any class that is having some abstract bhavior. So it may extend some concrete class therefor it may have concrete behavior for whatever it has extended from the concrete class. But it may well add *extra* abstract behavior by adding its own abstract methods.
So it will be having concrete methods from extended class + its own abstract methods. Therefore it has to be abstract.

/* concrete class */
class Draw{
void drawShape(){
//implementation provided..
}
}

/* Abstract Class */
abstract class Painting extends Draw{
void fillColor(); //no implementation provided..
}

Thanks!
Rohit Nath
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at sun tutorial http://java.sun.com/docs/books/tutorial/java/IandI/abstract.html

Conceptual view (very simplified and inaccurate): Abstract class is class that MUST be implemented (in some way) before use.

Purely from view of java language: abstract class is any class that have keyword abstract in declaration.

abstract class MyAbstractVector extends Vector { }

.. this horrible think is abstract class too for example :-(

Any attempt to create instance of abstract class ends with error.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic