• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

abstract class

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI
I would like to know is there any way we can create instance of abstract class.Beacuse we can define normal methods(non-static) in an abstract class,so how can we call this methods without creating instance of the class.And if we cant call these methods ,then whats the use of defining normal methods in abstract class.
Also i want to know what is the use of defining constructor in an abstract class???If we cant instantiate this class,then its constructer is never going to get called.
 
Ranch Hand
Posts: 1252
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by venkatesh pendharkar:
HI
I would like to know is there any way we can create instance of abstract class.Beacuse we can define normal methods(non-static) in an abstract class,so how can we call this methods without creating instance of the class.And if we cant call these methods ,then whats the use of defining normal methods in abstract class.
Also i want to know what is the use of defining constructor in an abstract class???If we cant instantiate this class,then its constructer is never going to get called.



Hope this example would help you some how and you may proceed further.

Carefully read this example and then you may want to raise your another question clearly as it is vast topic....

 
venkatesh pendharkar
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Sharma ji.
SO that means when we create a sample object ;constructor of class abc gets called & thus we can get construcor of abstract class run(by creating object of its subclass).And the non abstract methods will be directly available to the subclass to use.
So i think normal methods in the abstract class will be available only to its subclass & we cant use them anywhere outside the class(by creating instance).
am i correct sharmaji?
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pretty much yes, that's the purpose of abstract classes.

However, whatever access modifiers you apply to methods in an abstract class still apply. So if an abstract class has a public method, then any calling code can call that method on an instance, but if a private method exists in the abstract class, then not even subclasses wont be able to call it.
[ November 15, 2006: Message edited by: Andy Morris ]
 
venkatesh pendharkar
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it Andy,thanks for helping me out in this
 
I don't like that guy. The tiny ad agrees with me.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic