This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

abstarct class

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can an abstract class extend concrete class?
 
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
 
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
 
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!