• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

abstract

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
even abstract classes can have constructors but someone can explain how to make use of the constructor of the abstract class
 
Sheriff
Posts: 67269
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From a class that extends the abstract class.
 
sandeep Talari
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no it doesn't work and it didn't work.
 
sandeep Talari
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to make use of the constructor of the abstract class . Can anybody kindly illustrate it.
 
Bear Bibeault
Sheriff
Posts: 67269
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by sandeep Talari:
no it doesn't work and it didn't work.


You certainly give up quickly. Perhaps you should take the time and describe what you did and why you think it "didn't work" before just dismissing it?
 
sandeep Talari
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please explain


abstract class HelloWorld
{
HelloWorld()
{
System.out.println("hello world");

}
public void rin()
{
}
}
class ManageAbstract extends HelloWorld
{
public static void main(String[] ars)
{
HelloWorld hw = new HelloWorld();
}
}
this is not working .

you can illustrate
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The fact that abstract classes have constructors does not remove the fact that you cannot instanciate an abstract class. You wrongly assume that you can call "new" on any class having a constructor. The golden rule is : you can't instanciate abstract classes. Now, you should think of what would happen with the following code : HelloWorld hw = new ManageAbstract();
 
sandeep Talari
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank for the reply.In the above given code at what situations the constructor of the abstract class runs.Here, System.out.println("hello world"); when it is going to run,Explain .
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know that all constructors from the inheritance tree will be invoked. So what will happen if you extend an abstract class ? No exception to the rule. Its constructor will also be invoked,
 
sandeep Talari
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks its very clear...
 
Bear Bibeault
Sheriff
Posts: 67269
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said in my first reply.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!