Results 1 to 7 of 7
Thread: abstract sub-class
- 05-15-2008, 05:50 PM #1
Member
- Join Date
- Dec 2007
- Posts
- 17
- Rep Power
- 0
- 05-15-2008, 07:51 PM #2
Yep,
Here is an example,
Guess the output....Java Code:public class test extends B{ public test(){ this.printA(); this.printB(); } public static void main(String args[]){ new test().printA(); } } abstract class B extends A{ public void printA(){ System.out.println("class B"); } } abstract class A{ public void printB(){ System.out.println("class A"); } }freedom exists in the world of ideas
- 05-16-2008, 10:57 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
feniger got a nice example. :)
As that example, you have keep in mind two things.
1. Abstract class can be subclassed, as you can see.
2. Abstract classes cannot instantiate. If you do such a things, in compile time, got an error that abstract class cannot be instantiate.
- 05-18-2008, 09:00 AM #4
At any level in the class hierarchy you can declare an abstract class.
Java Code:package jf.acls; public class Concrete { @Override public String toString() { return "Concrete"; } } package jf.acls; public abstract class Abstract extends Concrete { @Override public String toString() { return "Abstract extends Concrete"; } public abstract int getTheNumber(); }Daniel @ [www.littletutorials.com]
Language is froth on the surface of thought
- 05-21-2008, 03:57 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 05-21-2008, 07:04 AM #6
I think his question was if it is possible to extend a concrete class (non-abstract) with an abstract class. And I said yes :) Abstract extends Concrete. I just wanted to make it clear that an abstract class can exist lower in the hierarchy, not only at the top. I hope it is clear now :) because if I continue to explain it will become really messy and unclear. LOL
Daniel @ [www.littletutorials.com]
Language is froth on the surface of thought
- 05-21-2008, 07:10 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Sure, I got the point. Thanks.
Similar Threads
-
Can this be done using abstract class??
By romina in forum New To JavaReplies: 6Last Post: 03-02-2009, 12:46 PM -
Interface Vs Abstract Class
By javarishi in forum New To JavaReplies: 5Last Post: 06-15-2008, 05:43 AM -
what is the Priority for execution of Interface class and a Abstract class
By Santoshbk in forum Advanced JavaReplies: 0Last Post: 04-02-2008, 07:04 AM -
Abstract Class
By gapper in forum New To JavaReplies: 4Last Post: 01-31-2008, 01:25 PM -
Abstract Class question
By maa11235 in forum New To JavaReplies: 1Last Post: 01-05-2008, 10:30 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks