Methods and Constructors

Quiz Guidelines

 

Multiple Choice Question

QID: 
449

Given a class named Test, which of these would be valid definitions for the constructors for the class?

Select 1 option

A. Test(Test b) { }
B. Test Test( ) { }
C. private final Test( ) { }
D. void Test( ) { }
E. public static void Test(String args[ ] ) { }

Multiple Choice Question

QID: 
448

Which of these statements are true?

Select 2 options

A. All classes must explicitly define a constructor.
B. A constructor can be declared private.
C. A constructor can declare a return value.
D. A constructor must initialize all the member variables of a class.
E. A constructor can access the non-static members of a class.

Multiple Choice Question

QID: 
447

Question 32:

Which of the following are true about the "default" constructor?

Select 1 option

A. It is provided by the compiler only if the class and any of its super classes does not define any constructor.
B. It takes no arguments.
C. A default constructor is used to return a default value.
D. To define a default constructor, you must use the default keyword.
E. It is always public.

Multiple Choice Question

QID: 
446

What will be the result of attempting to compile the following program?

public class TestClass{
long l1;
public void TestClass(long pLong) { l1 = pLong ; } //(1)
public static void main(String args[]){
TestClass a, b ;
a = new TestClass(); //(2)
b = new TestClass(5); //(3)
}
}

Select 1 option

A. A compilation error will be encountered at (1), since constructors should not specify a return value.
B. A compilation error will be encountered at (2), since the class does not have a default constructor.
C. A compilation error will be encountered at (3).
D. The program will compile correctly.
E. It will not compile because parameter type of the constructor is different than the type of value passed to it.

True or False

QID: 
303

You can call only public and protected constructors of the super class from a subclass if the subclass is not in the same package because only those are inherited.

Select 1 option

A. True
B. False
 

Pages