0% found this document useful (0 votes)
140 views45 pages

MCQ Test 1 - Constructors

This document contains a model test for Class X students with questions on constructors in Java. It has two sections - Section A with 10 multiple choice questions and Section B with 5 fill in the blank and 5 short answer questions. The multiple choice questions cover topics like what gets called when an object is created, constructor types, default constructors, and overloaded constructors. The fill in the blank questions test knowledge of implicit/default constructors, constructor as a method, parameter passing in constructors, and polymorphism. The short answer questions involve writing code snippets related to constructor overloading and implementing a Book class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
140 views45 pages

MCQ Test 1 - Constructors

This document contains a model test for Class X students with questions on constructors in Java. It has two sections - Section A with 10 multiple choice questions and Section B with 5 fill in the blank and 5 short answer questions. The multiple choice questions cover topics like what gets called when an object is created, constructor types, default constructors, and overloaded constructors. The fill in the blank questions test knowledge of implicit/default constructors, constructor as a method, parameter passing in constructors, and polymorphism. The short answer questions involve writing code snippets related to constructor overloading and implementing a Book class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

CLASS X - SEM 1

MODEL TEST 1
Constructors
MCQ
Section A [30 Marks]
Question 1 [Choose the correct answer] [10 x 1]

(a)Which unit of the class gets called, when the


object of the class is created?

(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) (ii) & (iv)


(2) All of the above
(3) (i),(ii) & (iv)
(4) None of the above
(c) Which type does the constructor do not
require?

(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) Compilation error


(2) Runtime error
(3) Compilation and runs successfully
(4) Only String return type is allowed
(f) The constructor is of how many
types?

(1) 1
(2) 3
(3) 2
(4) 6
(g) How many parameters are accepted
by a default constructor ?

(1) Only One


(2) As Many as possible
(3) Not even one
(4) None of the above
(h) What best describes the purpose of
a class constructor?

(1) Initialize the fields in the object.


(2) Determines the amount of space
needed for an object and creates the
object.
(3)Names the new object.
(4) Creates extra spaces in the memory.
(i) What is default accessibility modifier
of 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]

(a) The constructor generated by the compiler is


known as ………………….constructor.

(1) parameterized
(2) implicit
(3) explicit
(4) default
(b) A constructor is a special ………… of
a class.

(1) Data type


(2) Method
(3) Instantiation
(4) Object
(C) A default constructor is used to …………
the data members by any dummy value.

(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 …………………

(1) does not define a constructor at all.


(2) defines at least one constructor with
arguments
(3) defines a parameterized constructor
(4) None of these
(i) The placement of a constructor inside a
class should be ……………………………

(1) Always at the beginning of class


(2) Always at the end of class
(3) Anywhere in the class
(4) None
(j) Memory is allocated to an object
once the execution of ………………… is
over in Java language.

(1) main method


(2) constructor
(3) destructor
(4) None
Question 3[Give the output for the following] [5 x 2]

(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.

public class (a)…………


{ (a)
String code; (b)………… title; double price;

public Book(String (c)……………, String t, double pr) (1) class book


{
code=bookCode; (2) Book
title=t; (3) book
price=(d)………..;
} (4) Book

public String getcode()


{
return (e)…………….;
}
Question 5
WAP to implement a Book class that stores the details of a book such as its
code, title, and price.

public class (a)…………


{ (b)
String code; (b)………… title; double price;

public Book(String (c)……………, String t, double pr) (1) String


{
code=bookCode; (2) String class
title=t; (3) “String”
price=(d)………..;
} (4) t

public String getcode()


{
return (e)…………….;
}
Question 5
WAP to implement a Book class that stores the details of a book such as its
code, title, and price.

public class (a)…………


{ (c)
String code; (b)………… title; double price;

public Book(String (c)……………, String t, double pr) (1) code


{
code=bookCode; (2) Code
title=t; (3) bookCode
price=(d)………..;
} (4) bookcode()

public String getcode()


{
return (e)…………….;
}
Question 5
WAP to implement a Book class that stores the details of a book such as its
code, title, and price.

public class (a)…………


{ (d)
String code; (b)………… title; double price;

public Book(String (c)……………, String t, double pr) (1) price


{
code=bookCode; (2) double
title=t; (3) obj.pr
price=(d)………..;
} (4) pr

public String getcode()


{
return (e)…………….;
}
Question 5
WAP to implement a Book class that stores the details of a book such as its
code, title, and price.

public class (a)…………


{ (e)
String code; (b)………… title; double price;

public Book(String (c)……………, String t, double pr) (1) code


{
code=bookCode; (2) double
title=t; (3) bookCode
price=(d)………..;
} (4) book

public String getcode()


{
return (e)…………….;
}
Question 6 [5x2]
WAP that implements a Temperature class that stores a temperature in
Fahrenheit and provides functionality to convert the temperature to Celsius
also. public double getTemp()
class Temperature {
{ return (d)……………;
double temp; }
public (a)………………………
{ public static void main(String arg[])
temp=92; {
} Temperature dayTemp=new Temperature(94);
System.out.println(“Temp in Fahrenheit is :” + dayTemp.getTemp());
public Temperature(double t)
System.out.println(“Temp in Celsius is :” + dayTemp. (e)………… );
{ }
(b)………… = t; }
} (a)
public double convert2Celcius()
{ (1) Temperature
double Cel=(5.0/9)*(temp-32); (2) Temperature();
(c)………… Cel; (3) Temperature()
} (4) temperature
Question 6 [5x2]
WAP that implements a Temperature class that stores a temperature in
Fahrenheit and provides functionality to convert the temperature to Celsius
also. public double getTemp()
class Temperature {
{ return (d)……………;
double temp; }
public (a)………………………
{ public static void main(String arg[])
temp=92; {
} Temperature dayTemp=new Temperature(94);
System.out.println(“Temp in Fahrenheit is :” + dayTemp.getTemp());
public Temperature(double t)
System.out.println(“Temp in Celsius is :” + dayTemp. (e)………… );
{ }
(b)………… = t; }
} (b)
public double convert2Celcius()
{ (1) temp
double Cel=(5.0/9)*(temp-32); (2) Temperature
(c)………… Cel; (3) t
} (4) double t
Question 6 [5x2]
WAP that implements a Temperature class that stores a temperature in
Fahrenheit and provides functionality to convert the temperature to Celsius
also. public double getTemp()
class Temperature {
{ return (d)……………;
double temp; }
public (a)………………………
{ public static void main(String arg[])
temp=92; {
} Temperature dayTemp=new Temperature(94);
System.out.println(“Temp in Fahrenheit is :” + dayTemp.getTemp());
public Temperature(double t)
System.out.println(“Temp in Celsius is :” + dayTemp. (e)………… );
{ }
(b)………… = t; }
} (c)
public double convert2Celcius()
{ (1) double
double Cel=(5.0/9)*(temp-32); (2) return
(c)………… Cel; (3) temp=
} (4) System.out.print()
Question 6 [5x2]
WAP that implements a Temperature class that stores a temperature in
Fahrenheit and provides functionality to convert the temperature to Celsius
also. public double getTemp()
class Temperature {
{ return (d)……………;
double temp; }
public (a)………………………
{ public static void main(String arg[])
temp=92; {
} Temperature dayTemp=new Temperature(94);
System.out.println(“Temp in Fahrenheit is :” + dayTemp.getTemp());
public Temperature(double t)
System.out.println(“Temp in Celsius is :” + dayTemp. (e)………… );
{ }
(b)………… = t; }
} (d)
public double convert2Celcius()
{ (1) Cel
double Cel=(5.0/9)*(temp-32); (2) return
(c)………… Cel; (3) temp
} (4) cel
Question 6 [5x2]
WAP that implements a Temperature class that stores a temperature in
Fahrenheit and provides functionality to convert the temperature to Celsius
also. public double getTemp()
class Temperature {
{ return (d)……………;
double temp; }
public (a)………………………
{ public static void main(String arg[])
temp=92; {
} Temperature dayTemp=new Temperature(94);
System.out.println(“Temp in Fahrenheit is :” + dayTemp.getTemp());
public Temperature(double t)
System.out.println(“Temp in Celsius is :” + dayTemp. (e)………… );
{ }
(b)………… = t; }
} (e)
public double convert2Celcius()
{ (1) convert2Celcius()
double Cel=(5.0/9)*(temp-32); (2) Temperature
(c)………… Cel; (3) dayTemp
} (4) convert2Celcius
Thank You
Portions
Next MCQ

Class as the basis of all computation


&
User-defined Methods

You might also like