Java comes with a set of special set of Constructor Properties.
List of Constructor Properties
What can not?
1. "A constructor cannot be abstract, static, final, native, strictfp, or synchronized".
2. Interface cannot have constructor.
3. Constructor cannot return a value.
What can?
1. A constructor can be private.
2. Abstract class can have constructor.
3. A constructor can be overloaded.
Instance variables and methods of a class are known as members of a class. Constructors are not members. For this reason, constructors cannot be inherited; but can be accessed by a subclass. What does it mean? Constructors cannot be called with objects like d1.display(). To access a constructor create an object or access with subclass constructor (explicitly with super()).
Constructors are not inherited; only members (variables and methods) are inherited. So declaring a constructor final does not have any meaning as constructors cannot be overridden.
If a constructor is abstract, it cannot be implemented (cannot have body or no code). A constructor should have a body as constructor gives properties to an object at the time of creation itself.
Constructors are called when an object is created but cannot be called like a method (like d1.show()) with an object; so no necessity for a constructors to be static.
A constructor should not be synchronized as it locks the object in creation and thereby, as long as the object is not created no other object can be instantiated .
The methods which cannot be executed by JVM alone and depends on the underlying OS are known as native methods. Native methods execution is slow and for this reason many native methods throw a checked exception.
Declaring a constructor native is unnecessarily inviting trouble and also a subclass constructor cannot call super class constructor easily.
Pass your comments on this tutorial "Constructor Properties".
This is the right blog for anybody who really wants to understand this topic. Its really a great and useful piece of information. Im glad that you shared this helpful information with us.
Please stay us up to date like this. Thanks for sharing.
Constructors in java are used for creating class objects. Constructor with parameter means you could initialize class object with some initial properties setup. For more understanding you could follow this java tutorial.
Sir … i haven’t got this very clearly, why a constructor can be private and not static?can u plz explain?
http://way2java.com/oops-concepts/static-constructor/
http://way2java.com/oops-concepts/private-constructor/
superb blog
To access a constructor create an object or access with subclass constructor (explicitly with super()). sir,what is the need of super keyword eventhough the constructer cannot be overridden?
It is just to access the needed super class constructor.
Only One word to Explain this Site : AWESOME :) What a great work i have found on Internet while searching for Java Tutorials. Its a great Blog to Read, Learn and be a Expert in java. I totally Recommend to Bookmark all the Readers, in your browser.
Just one suggestion, if you can add simple examples with the statements of any topic, then it would be very helpful to understand the concepts.
what happen when an object is created in a subclass in a inheritance hierarchy level? are all the superclass constructors called? if not which one is called?
thanks for this work, best site to learn java.
regards from Spain.
Yes, all super class default constructors are called implicitly.
Hi Rao Sir,
It’s very nice and best blog that provide the java concepts.It’s my experience there are no any best blog in the goggle site that can solved our confusion.
I appreciate this blog.It’s very helpful for IT professionals and preparation of java learning and interview facing.
After reading this blog i am not go any other web site and blog.
This blog provides the depth knowledge of java.
Dear Sir, if you can provide the advance java then it’s very helpful to the various IT professionals.
Thanks & Regards,
Sujeet Sharma
I do Advanced Java within two months. Tell all your friends also to utilize this web site.
thanq u sir
As constructors are not overridden can we say they are implicitly final?
No, constructor cannot be final as a principle.
I mean sir on the main page where there are lots of listings…
Sir the only thing i find difficult is searching things on the site..
If this can be sorted out ,it would be really appreciated.
great tutorialss……rally worth to read!!!!!!!!!!
Hello Satish,
Thanks for your comments. Your comments are encouraging to write more and more. Also pass me of negative comments that include what you still expect.
S. Nageswara Rao,
Hyderabad, India.