abstarct class
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
can an abstract class extend concrete class? 

posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
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
Pranav Kumar
posted 18 years ago
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
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
R.N
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
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.
<a href="http://www.java-tips.org/java-tutorials/tutorials/" target="_blank" rel="nofollow">Java Tutorials</a> | <a href="http://www.planet-java.org" target="_blank" rel="nofollow">Java Weblog</a> | <a href="http://computer-engineering.science-tips.org" target="_blank" rel="nofollow">Computing Articles</a>
| I would challenge you to a battle of wits, but I see you are unarmed - shakespear. Unarmed tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |






