Constructor overloading issue in java -


i learing core java , practicing it. understand concept of method overloading. when run below program shows error "

constructor methodover in class methodover cannot applied given types;         methodover m2 = new methodover();                         ^   required: int,int   found: no arguments   reason: actual , formal argument lists differ in length" 

please find code below , help.. learning.

public class methodover {        int x;     int y;       methodover(int a, int b)     {         x=a;         y=b;         system.out.println("the values assigned are" +x+ "and" +y);      }      void multiply(methodover obj)     {   obj.x = 2;         obj.y = 2;         system.out.println("the multiplication result object passed is" +obj.x*obj.y );      }     public static void main(string[] args)     {         methodover m1 = new methodover(5,6);         methodover m2 = new methodover();         m2.multiply(m1);      }  } 

while playing constructor, use default constructor avoid run time exceptions.define default constructor in code..

 methodover()  {       //initialize default values.       this(0, 0);  }  

Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -