Results 1 to 16 of 16
Thread: General Discussion on Abstract
- 04-28-2008, 11:14 AM #1
General Discussion on Abstract
Hello All,
I started this thread just to discuss general Java topics. I am not asking the question i just wanted to share knowledge and want to discuss with all members to get more ideas. It think you will like this.
Your Comments are Welcome.
So let's Start.
Todays Topic : Abstract in Java
1) In which scenario one should go for Abstract Class rather than Interface.
2) Can Abstract class have contractor? If yes then when it is called? and can it be private?
3) Where we can use abstract keyword in Java(like before class declaration,variable declaration etc.).
sanjeev,संजीव
- 04-28-2008, 11:37 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I use interface rather than abstract, if I can see that something is change frequently. I mean If you want to make changes. may be in design, make them as interface. Abstract class may have default implementation. That is because, abstract class only allowed to subclasses.
Abstract class can have constructor and, it can be private.
What you mean here? Looking how to define an abstract class?
Java Code:abstract public class testClass() { }
- 04-28-2008, 11:50 AM #3
When it is called?? and are you sure that it can be private.??
Please do not try first give the answer.
No dear, where else .......Abstract keyword is used.What you mean here? Looking how to define an abstract class?
Java Code:abstract public class testClass() { }
Thanks for your reply...but i want other members reply too.:)
Last edited by sanjeevtarar; 04-28-2008 at 11:52 AM.
sanjeev,संजीव
- 04-28-2008, 11:53 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 04-28-2008, 11:56 AM #5
- 05-02-2008, 07:18 AM #6
Hello Eranga,
You haven't answer....sanjeev,संजीव
- 05-02-2008, 07:34 AM #7
Why would you ever make a private constructor that just sounds stupid. Also I use abstract when I want to extend something. like lets say I have a customer generator. Then I want to have a uniform customer generator, and a bell curve customer generator. If I made the customer generator an interface there would be a lot of dupliction of code whereas if I make customer generator class abstract then uniform would have to just have decide when to create a customer and not have to worry about actually generating a customer.
My IP address is 127.0.0.1
- 05-02-2008, 07:38 AM #8
There is no use of private constructor in Abstract class. There is no use of abstract class until or unless it is extended. And if one make a private constructor then there will be no use of abstract class.....
THEN WHY COMPILER PERMITS TO MAKE PRIVATE CONSTRUCTOR...IS THERE ANY SCENARIO WHERE IT IS USED IN ABSTRACT CLASS.sanjeev,संजीव
- 05-02-2008, 07:46 AM #9
The compiler allows private constructors if you want to have a class make an object inside itself and only inside its self
My IP address is 127.0.0.1
- 05-02-2008, 07:49 AM #10
- 05-02-2008, 07:59 AM #11
- 05-02-2008, 08:07 AM #12
- 05-02-2008, 08:09 AM #13
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Ok, just check these three classes.
Java Code:abstract class AbstractClass { protected AbstractClass() { System.out.println("Abstract class constructor call."); } public abstract void distinctMethod(); public void ususalMethod() { System.out.println("A ususal method is call."); distinctMethod(); } }Java Code:public class AbstractDemo { public static void main(String args[]) { AbstractClass ref; //ref = new AbstractClass() { ref = new DeafultClass(); ref.ususalMethod(); } }Java Code:class DeafultClass extends AbstractClass{ public void distinctMethod() { System.out.println("Another method is call."); } }
- 05-05-2008, 05:14 PM #14
Member
- Join Date
- May 2008
- Posts
- 22
- Rep Power
- 0
I can understand how an abstract class might use a package/protected/public constructor (if it can be called by super()), but I guess private+abstract constructors are unreasonable... But would anyone ever put a private constructor in an abstract class, even on accident?
- 05-06-2008, 03:50 AM #15
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Sanjeev, you don't have any comments on my example? :)
- 05-06-2008, 06:16 AM #16
Similar Threads
-
Can this be done using abstract class??
By romina in forum New To JavaReplies: 6Last Post: 03-02-2009, 12:46 PM -
Error! "filename" is not abstract and does not override abstract method...
By hasani6leap in forum New To JavaReplies: 6Last Post: 10-27-2008, 12:25 AM -
Abstract Class
By gapper in forum New To JavaReplies: 4Last Post: 01-31-2008, 01:25 PM -
GUI for Abstract...
By judepereira in forum AWT / SwingReplies: 0Last Post: 01-04-2008, 08:40 AM -
How to set General options in NetBeans IDE
By JavaForums in forum NetBeansReplies: 0Last Post: 08-02-2007, 12:11 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks