• 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
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Calling Constructors

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi everybody,
I want to know whether Constructors can be called other than when a class is instantiated?
Also can methods or classes be static and abstract at the same time?
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No methods and classes cannot be abstract ans static, that is not allowed.
There is now way to call a constructor from any other class directly, only subclass we can use super();
otherwise only way to call the constructor is by using new();
can anyone else also clarify?
[This message has been edited by Milind Deodhar (edited December 07, 2000).]
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are correct Milind. Constructors are only called when the class is initialized and you can call another constructor within a constructor with the call this() and you can call the constructor of the immediate super class with super. One thing they try to trick you on is whether you can call a specific constructor of your superclass's superclass like super().super() or something like that, but there is no way you can call further up the hieracrhy other than the superclass.
Also if you use this() or super() they need to be the first call in the constructor, therefore you can't use super and this in the same constructor.
You are also correct about abstract and static.
Bill
 
Willie Smits can speak 40 languages. This tiny ad can speak only one:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic