Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-28-2008, 12:14 PM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
sanjeevtarar is on a distinguished road
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,संजीव
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-28-2008, 12:37 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,322
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by sanjeevtarar View Post

1) In which scenario one should go for Abstract Class rather than Interface.
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.

Quote:
Originally Posted by sanjeevtarar View Post
2) Can Abstract class have contractor? If yes then when it is called? and can it be private?

Abstract class can have constructor and, it can be private.



Quote:
Originally Posted by sanjeevtarar View Post
3) Where we can use abstract keyword in Java(like before class declaration,variable declaration etc.).
What you mean here? Looking how to define an abstract class?

Code:
abstract public class testClass() { }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-28-2008, 12:50 PM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
sanjeevtarar is on a distinguished road


Quote:
Originally Posted by Eranga View Post


Abstract class can have constructor and, it can be private.
When it is called?? and are you sure that it can be private.??
Please do not try first give the answer.

Quote:
What you mean here? Looking how to define an abstract class?

Code:
abstract public class testClass() { }
No dear, where else .......Abstract keyword is used.



Thanks for your reply...but i want other members reply too.

__________________
sanjeev,संजीव

Last edited by sanjeevtarar : 04-28-2008 at 12:52 PM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-28-2008, 12:53 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,322
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by sanjeevtarar View Post


Thanks for your reply...but i want other members reply too.

Until that any comments

I can see that, it can be private bold. Are you interesting on it, right...
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-28-2008, 12:56 PM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
sanjeevtarar is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Until that any comments

I can see that, it can be private bold. Are you interesting on it, right...
Ok let me know one thing when abstract class constructor is called.
Because we never instantiate abstract class.

and then think about private constructor. and give some clarification on that.
__________________
sanjeev,संजीव
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-02-2008, 08:18 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
sanjeevtarar is on a distinguished road
Hello Eranga,

You haven't answer....
__________________
sanjeev,संजीव
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-02-2008, 08:34 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 223
Zosden is on a distinguished road
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.
__________________
Definition of Impossible = making a good game in Java.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-02-2008, 08:38 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
sanjeevtarar is on a distinguished road
Quote:
Originally Posted by Zosden View Post
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.
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,संजीव
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-02-2008, 08:46 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 223
Zosden is on a distinguished road
The compiler allows private constructors if you want to have a class make an object inside itself and only inside its self
__________________
Definition of Impossible = making a good game in Java.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 05-02-2008, 08:49 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
sanjeevtarar is on a distinguished road
Quote:
Originally Posted by Zosden View Post
The compiler allows private constructors if you want to have a class make an object inside itself and only inside its self
Then what is the use of there .... making Object Inside....
__________________
sanjeev,संजीव
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 05-02-2008, 08:59 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 223
Zosden is on a distinguished road
Here is this topic in another forum Topic
__________________
Definition of Impossible = making a good game in Java.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 05-02-2008, 09:07 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
sanjeevtarar is on a distinguished road
Quote:
Originally Posted by Zosden View Post
Here is this topic in another forum Topic
Zosden, I know it very well and i was just discussing here to share/get some knowledge on that.
__________________
sanjeev,संजीव
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 05-02-2008, 09:09 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,322
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by sanjeevtarar View Post
Hello Eranga,

You haven't answer....
Ok, just check these three classes.

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(); } }
Code:
public class AbstractDemo { public static void main(String args[]) { AbstractClass ref; //ref = new AbstractClass() { ref = new DeafultClass(); ref.ususalMethod(); } }
Code:
class DeafultClass extends AbstractClass{ public void distinctMethod() { System.out.println("Another method is call."); } }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 05-05-2008, 06:14 PM
Member
 
Join Date: May 2008
Posts: 22
Jesdisciple is on a distinguished road
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?
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 05-06-2008, 04:50 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,322
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Sanjeev, you don't have any comments on my example?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best?Vote Now
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 05-06-2008, 07:16 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
sanjeevtarar is on a distinguished road
Quote:
Originally Posted by Jesdisciple View Post
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?
exactly Jesdisciple ..... There is no use of private constructor in abstract class.
__________________
sanjeev,संजीव
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Abstract Class gapper New To Java 4 01-31-2008 02:25 PM
Error! "filename" is not abstract and does not override abstract method... hasani6leap New To Java 4 01-06-2008 05:59 PM
GUI for Abstract... judepereira AWT / Swing 0 01-04-2008 09:40 AM
How to set General options in NetBeans IDE JavaForums NetBeans 0 08-02-2007 01:11 PM
Can this be done using abstract class?? romina New To Java 2 07-26-2007 10:09 AM


All times are GMT +3. The time now is 09:27 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org