When I write a simple parametrised constructor program, it compiles and runs in the command line.
However when it is executed within the Eclipse IDE, I received the following exception:
Exception in thread "main" java.lang.NoSuchMethodError: a_constructor.Test.(II)V at a_constructor.ParametrizedConstructor.main(ParametrizedConstructor.java:15).
Code :
//write a java program which listed the concept of parameterized constructor
class Test {
int a,b;
Test (int x, int y) {
a=x;
b=y;
System.out.println("========================");
System.out.println("value of a=" +a);
System.out.println("value of b=" +b);
System.out.println("========================");
}
}
public class ParametrizedConstructor {
public static void main(String[] args) {
Test t1=new Test(10,20);
Test t2=new Test(100,200);
Test t3=new Test(1000,2000);
}
}
The ParametrizedConstructor
code is clean and doesn't have any issues.
Try:
Alternate Solutions:
ParametrizedConstructor.java
(i.e.., public class)For References - Check also the below links for better understanding: