• Post Reply Bookmark Topic Watch Topic
  • New Topic

abstarct class  RSS feed

 
abhinava srivastava
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can an abstract class extend concrete class?
 
Panav Kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
 
Rohit Nath
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • 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
 
Neerav Narielwala
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!