Menu
Topics Index
...
`

Creating objects for class


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating objects for class
What will be the output of the following program?
public class InitializationTest {
    int number;
    public void InitializationTest(int number) {
        this.number = number;
        System.out.println(number);
    }
    public static void main(String... strings) {
        InitializationTest obj1, obj2;
        obj1 = new InitializationTest();
        obj2 = new InitializationTest(5);
    }
}

A. 5
B. Compile time Error since no default constructor
C. Compile time Error since no parameterized constructor
D. Compilation Error or Runtime Error for some other reason
Topic: this Keyword In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

answer B in this code constructor is not intialised properly . so answer is B

Posted by Sivani Reddy Kakuru    2014-05-28 13:05:42


answer is b... as it doesnt have default constructr...if parametrisd constructr is defined then we cant create object of default construcr unles we define it

Posted by Vijay Kumar    2014-05-28 13:08:16


ans : c parameterized constructer not defined... default constructor is optional...parametarized constructor is no optional on..

Posted by Ananda Kumar    2014-05-28 14:30:57


Congratulations Ananda Kumar. You are  this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-05-29 04:57:19


© meritcampus 2019

All Rights Reserved.

Open In App