简体   繁体   中英

Java constructor overloading

public class Drop_ABCD {
  private int First_number;
  private int Second_number;
  //Have one constructor overloaded with only one int 

  public Drop_ABCD(int First_number){
    this.First_number = First_number;
  }

  //Both getters & Setters set for First_number & Second_number
}

In the main class

Drop_ABCD abcd_obj = new Drop_ABCD(25485929);
ABCD_Main abcd_xml_drop = new ABCD_Main("drop",abcd_obj);

But when the XML is generated it as taken both First_number with 2548592 and Second_number with 0 ,

Whenever the data type overloaded is 'int' , it populates all the other values of int types are set to 0 .

I don't want Second_number to be included at all, but it is included with a default value 0

  1. Work on your conventions. Where can I find the OFFICIAL Java Coding/Style Standards?

  2. Familiarize the language semantics for primitives in java. https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

  3. Change the primitives to the object wrapper (int to Integer) and check on the difference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM