Determine output:
class MyClass{
int i;
int j;
public MyClass(int i, int j){
this.i = i;
this.j = j;
}
public void call(){
System.out.print("One");
}
}
public class Test{
public static void main(String args[]){
MyClass m = new MyClass(); //line 1
m.call(); //line 2
}
}
class MyClass{
int i;
int j;
public MyClass(int i, int j){
this.i = i;
this.j = j;
}
public void call(){
System.out.print("One");
}
}
public class Test{
public static void main(String args[]){
MyClass m = new MyClass(); //line 1
m.call(); //line 2
}
}A. One
B. Compilation fails due to an error on line 1
C. Compilation fails due to an error on line 2
D. Compilation succeed but no output.
Answer: Option B

If no constructor created,then the system check for default constructor; but here parameterized constructor defined,but calling default-so compile time error
Here the class defines a parameterized constructor due to which the default constructor is not inserted by jvm.When the new intance is created,it does not get the default constructor resulting in compilation error.
when the compiler doesn't have a default constructor, won't it create a default constructor on its own?
Sai Krishna in line one, while the object is created a compiler, will look for no argument constructor in class but as it is not defined there it will result in compile time error.
please help with this