I am getting an error in my java program as : constructor Try1 in class Try1 cannot be applied to given types; -


i trying implement constructor overloading in java. think perfect shows error:

main.java:28: error: constructor tryme in class tryme cannot applied given types;

   tryme s=new tryme(1,1,2015);            ^   required: no arguments   found: int,int,int   reason: actual , formal argument lists differ in length 1 error . 

here code:

      import java.util.*;        class try1 {         int day,month,year;``         public void try1() {           day = 1;           month = 1;           year = 2015;         }          public void try1(int d,int m,int y) {           day = d;           month = m;           year = y;         }          public void seter() {           system.out.println(day+"/"+month+"/"+year);         }       }        class mdate {         public static void main(string []str) {           try1 t = new try1();           t.seter();           try1 s=new try1(1,1,2015);           s.seter();         }       } 

constructor not used explicit return type used void return type. have remove void constructor.

use constructor below :

       public try1() {            day = 1;            month = 1;            year = 2015;        }         public try1(int d, int m, int y) {            day = d;            month = m;            year = y;       } 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -