Examveda
Examveda

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
	}
}

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


This Question Belongs to Java Program >> Constructors And Methods

Join The Discussion

Comments ( 5 )

  1. Asna
    Asna :
    11 months ago

    If no constructor created,then the system check for default constructor; but here parameterized constructor defined,but calling default-so compile time error

  2. Kasturi Moghe
    Kasturi Moghe :
    6 years ago

    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.

  3. Shravya Yadav
    Shravya Yadav :
    6 years ago

    when the compiler doesn't have a default constructor, won't it create a default constructor on its own?

  4. Nitin Thakur
    Nitin Thakur :
    7 years ago

    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.

  5. Sai Krishna
    Sai Krishna :
    7 years ago

    please help with this

Related Questions on Constructors and Methods

What is a constructor in Java?

A. A special method to create instances of classes

B. A method used for mathematical calculations

C. A method to perform string manipulations

D. An exception handling mechanism