|
|
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.
|
|

04-28-2008, 12:14 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
|
|
|
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, 12:37 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,322
|
|
Originally Posted by sanjeevtarar
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.
Originally Posted by sanjeevtarar
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.
Originally Posted by sanjeevtarar
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?
abstract public class testClass() {
}
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best? Vote Now
|
|

04-28-2008, 12:50 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
|
|
Originally Posted by Eranga
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.
What you mean here? Looking how to define an abstract class?
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.
|
|

04-28-2008, 12:53 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,322
|
|
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Want to make your IDE the best? Vote Now
|
|

04-28-2008, 12:56 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
|
|
Originally Posted by Eranga
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,संजीव
|
|

05-02-2008, 08:18 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
|
|
|
Hello Eranga,
You haven't answer....
__________________
sanjeev,संजीव
|
|

05-02-2008, 08:34 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 223
|
|
|
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.
|
|

05-02-2008, 08:38 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
|
|
Originally Posted by Zosden
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,संजीव
|
|

05-02-2008, 08:46 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 223
|
|
|
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.
|
|

05-02-2008, 08:49 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
|
|
Originally Posted by Zosden
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,संजीव
|
|

05-02-2008, 08:59 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 223
|
|
Here is this topic in another forum Topic
__________________
Definition of Impossible = making a good game in Java.
|
|

05-02-2008, 09:07 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
|
|
Originally Posted by Zosden
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,संजीव
|
|

05-02-2008, 09:09 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,322
|
|
Originally Posted by sanjeevtarar
Hello Eranga,
You haven't answer....
Ok, just check these three classes.
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();
}
}
public class AbstractDemo {
public static void main(String args[]) {
AbstractClass ref;
//ref = new AbstractClass() {
ref = new DeafultClass();
ref.ususalMethod();
}
}
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
|
|

05-05-2008, 06:14 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 22
|
|
|
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, 04:50 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 1,322
|
|
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
|
|

05-06-2008, 07:16 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 237
|
|
Originally Posted by Jesdisciple
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,संजीव
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|