Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How many rules are there in Java Constructor Overloading?

  1. #1
    Junior Member
    Join Date
    Sep 2021
    Location
    Pune
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation How many rules are there in Java Constructor Overloading?

    Hi All, I just started learning Java and was reading the Constructor Overloading article. However, I am a bit confused about how many rules are there, three rules I have listed below ->

    - The constructor's name should match the name of the class.
    - A constructor cannot have a return type.
    - A Java constructor cannot use the keywords abstract, static, final, and synchronized.

    Are there any other rules that I am missing?


    Article that i was reading: https://www.scaler.com/topics/constr...ading-in-java/

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: How many rules are there in Java Constructor Overloading?

    Look at the java specification docs: https://docs.oracle.com/javase/specs...tml/index.html
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    supernerd007 (January 28th, 2022)

  4. #3
    Junior Member
    Join Date
    Apr 2023
    Location
    India
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How many rules are there in Java Constructor Overloading?

    Sir, I have gained complete knowledge on constructor overloading from this article. After reading this post, you will not have any confusion. You can understand syntax, features, rules to define a constructor, programs, and many more. I think you should visit once this tutorial to get the complete knowledge on constructor overloading. https://www.scientecheasy.com/2020/0...rloading.html/

  5. #4
    Junior Member
    Join Date
    Jan 2024
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How many rules are there in Java Constructor Overloading?

    Your understanding of the basic rules of Java constructor overloading is a great start

    Parameter Lists: In constructor overloading, you can have multiple constructors within a class that differ in the number or type of parameters they accept. This allows for flexibility in object initialization.

    Call to Another Constructor: You can also call one constructor from another within the same class using this() keyword. This is particularly useful for reducing redundancy in code and improving maintainability.

    Order of Constructors: When overloading constructors, it's essential to be mindful of the order in which they're defined within the class. Java resolves constructor calls based on the parameters provided, so having a clear understanding of the order of constructors can prevent unintended behavior.

    With these additional points in mind, your understanding of Java constructor overloading will be more easy. You'll find better resources at https://www.programminghomeworkhelp....va-assignment/.

Similar Threads

  1. Replies: 0
    Last Post: September 24th, 2018, 06:24 AM
  2. Testing Constructor Overloading using Eclipse
    By michael.duffy31 in forum Java IDEs
    Replies: 8
    Last Post: September 2nd, 2013, 01:01 AM
  3. constructor overloading
    By jamesjack in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 13th, 2013, 12:12 AM
  4. New to Java : Need help with my integers rules
    By MartinRR in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 29th, 2011, 01:14 PM