Constructor Properties Java

Constructor Properties Java


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

18 thoughts on “Constructor Properties Java

  1. Abiya

    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.

  2. vyshnav reddy

    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?

  3. An Kit

    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.

  4. Rafa

    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.

  5. Sujeet Sharma

    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

    1. S. Nageswara Rao, Sr.Faculty Post author

      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.

Leave a Reply

Your email address will not be published. Required fields are marked *