MCQ Test 1 - Constructors
MCQ Test 1 - Constructors
MODEL TEST 1
Constructors
MCQ
Section A [30 Marks]
Question 1 [Choose the correct answer] [10 x 1]
(1) Method
(2) Constructor
(3) Instance
(4) Constructor()
(b) Which of the following is true according to
the constructor?
(i) No return Type
(ii) Same as class name
(iii)No void
(iv)Called during object creation
(1) Data
(2) Object
(3) Return
(4) Overloaded
(d) Which keyword is used to represent the
current object ?
(1) new
(2) this
(3) return
(4) all of these
(e)What would be the behaviour, if the
constructor has a return type?
(1) 1
(2) 3
(3) 2
(4) 6
(g) How many parameters are accepted
by a default constructor ?
(1) public
(2) private
(3) Same as class accessibility modifier
(4) default
(j) Which constructor creates objects
by passing value to it.
(1) Parameterised
(2) Non Parameterised
(3) Default
(4) Copy
Question 2 [Fill in the blanks with the correct option] [10 x 1]
(1) parameterized
(2) implicit
(3) explicit
(4) default
(b) A constructor is a special ………… of
a class.
(1) Declare
(2) Initialize
(3) Create
(4) Invoke
(d) Choosing a suitable overloaded
constructor happens at ……………time in
Java.
(1) Compile-time
(2) Run time
(3) Default
(4) Connection
(e) A constructor gets ………….. at the time
of object creation.
(1) Removed
(2) Called
(3) Sorted
(4) Alloted
(f) Java constructor overloading
follows…………..principle in Object-Oriented
programming.
(1) Inheritance
(2) Encapsulation
(3) Polymorphism
(4) None
(g) Overloading of constructors in Java
means adding more than……………
constructors with the different
argument list.
(1) 1
(2) 2
(3) 3
(4) 8
(h) The compiler adds a default no-argument
constructor to a class if it …………………
(a)
public class Constructor9
{
Constructor9() (1) JAM JAM
{
show(); (2) No output
} (3) Compiler error
void show()
{
(4) None
System.out.println("JAM JAM");
}
public static void main(String[] args)
{
Constructor9 con = new Constructor9();
}}
(b)
public class TestingConstructor
{
void TestingConstructor()
{
System.out.println("Amsterdam");
} (1) Antarctica
TestingConstructor() (2) Amsterdam
{ (3) No output
System.out.println("Antarctica"); (4) Compiler error
}
public static void main(String[] args)
{
TestingConstructor tc = new TestingConstructor();
}
}
(c)
public class Constructor2
{
int count=10;
Constructor2(int count)
{
(1) Count=0
System.out.println("Count=" + count);
} (2) Count=10
(3) Compiler error
public static void main(String[] args) (4) None of the above
{
Constructor2 con = new Constructor2();
}
}
(d)
public class Constructor7
{
Constructor7(int a)
{
System.out.println("Book=" + a);
} (1) Book=50
Constructor7(float a)
{ (2) Pen=50.5
System.out.println("Pen="+ a ); (3) Compiler error
} (4) Pen=50.5f
public static void main(String[] args)
{
Constructor7 con = new Constructor7(50.5f);
}
}
(e)
public class Profile{
private Profile(int w) { // Line 1 (1) Wont compile because
System.out.print(w); Line 1 is private
} (2) 10 50
public static Profile() { //Line 5 (3) 50
System.out.print(10); (4) Wont compile because
} Line 5 , Constructor can’t
public static void main(String arg[]) be static
{
Profile obj=new Profile(50);
}
}
Section B [20 Marks]
Question 4 [5x1]
Constructor overloading:
class Smart
{
public Smart()
{ // statement
(a)
}
public Smart( (a)………)
{ // statement
(1) i
} (2) int i
public (b)………..( String str)
{ // statement
(3) i=0
} (4) None of these
public static void (c)…….. (String arg[])
{
Smart s=new (d)……………;
Smart ss=new Smart(10);
Smart st=new Smart((e)………………..);
}}
Question 4
Constructor overloading:
class Smart
{
public Smart()
{ // statement
(b)
}
public Smart( (a)………)
{ // statement
(1) static
} (2) smart1
public (b)………..( String str)
{ // statement
(3) Smart
} (4) Smart()
public static void (c)…….. (String arg[])
{
Smart s=new (d)……………;
Smart ss=new Smart(10);
Smart st=new Smart((e)………………..);
}}
Question 4
Constructor overloading:
class Smart
{
public Smart()
{ // statement
(c)
}
public Smart( (a)………)
{ // statement
(1) Input
} (2) main()
public (b)………..( String str)
{ // statement
(3) Main()
} (4) main
public static void (c)…….. (String arg[])
{
Smart s=new (d)……………;
Smart ss=new Smart(10);
Smart st=new Smart((e)………………..);
}}
Question 4
Constructor overloading:
class Smart
{
public Smart()
{ // statement
(d)
}
public Smart( (a)………)
{ // statement
(1) Smart
} (2) Smart()
public (b)………..(String str)
{ // statement
(3) smart
} (4) smart(“ ”)
public static void (c)…….. (String arg[])
{
Smart s=new (d)……………;
Smart ss=new Smart(10);
Smart st=new Smart((e)………………..);
}}
Question 4
Constructor overloading:
class Smart
{
public Smart()
{ // statement
(e)
}
public Smart( (a)………)
{ // statement
(1) String Java
} (2) “Java”
public (b)………..(String str)
{ // statement
(3) ‘java’
} (4) Java
public static void (c)…….. (String arg[])
{
Smart s=new (d)……………;
Smart ss=new Smart(10);
Smart st=new Smart((e)………………..);
}}
Question 5 [5x1]
WAP to implement a Book class that stores the details of a book such as its
code, title, and price.