0% found this document useful (0 votes)
23 views11 pages

Computer Exam 18

Uploaded by

raib35404
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)
23 views11 pages

Computer Exam 18

Uploaded by

raib35404
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/ 11

INCLUDED IN THIS SECTION

Multliple-Choice Questions (MCQs)

Solutions

Select the corect option from the choices a, b, c and d.

1. Which of the following


is not applicable for a constructor funcio.
a) It has the same name as the class. n?
b) It has no return-type
c)Itis usually used for initialisation.
d) It can be invoked using an object like any other member function.

2. If the name of a class is "Number, what can be the


constructor?
possible name for its
a) Number c) No
b) number
d) no
3. Which among the
following is a
a) Parameterised constructor
type of constructor?
b) Non-parameterised constructor c) Both a and b
d) None of these
4. If constructors
a) Parameter list
are
overloaded, what differentiates it?
b) Retum type c) Both a and b
d) None of these
5. What access
within the class?
specifier for a constructor allows
vou to create an object o
a) public
b) private
c) protected
d) default
6. Name the
type of constructor that gets invoked when an
which is initialised with the contents of objert
another obje
Exam18IC CATION
LICATIONS Question Bank -Class X
a) Copy constructor

b) Default constructor
c) Overloaded constructor
d) None of these

7. ao rise the type


Categoris
ot
object that can be
created without any
identifier.
name or

a) Temporary object
c) Both a and b
b)Anonymousobject
d) None of these

Predict the output ot the


tollowing program:
class T
intt 20;
TO
t 40;

public static void main(String argsl]) {


Ttl = new T();

System.out.println(t1.t);

a) 20 c) Compiler Error
b) 40 d) None of these

9. The following code contains one compilation error. Identify this error from
the following options.

public class Test {

Test)I1/| line 1
static void Test() { this(); } // ine 2

ine 3
public static void main(Stringl] args) { //
Test(;// line 4

a) At line 1, constructor Test must be marked public like its class


b) At line 2, constructor cal whether
ambiguity problem, compiler can't determine
A t line 3, compilation error,

a constructor

d) At line 4

is not true for static block?


Which of the following
0 variables.
a)ltis used to initialise static
loaded in the memory.
when a class gets
gets executed variables.
t can print the of instance
content

d) It hegins with the static keyword.


COMPUT
Exam18 ICSE Sem I& II
c) Maybe
d) Not sure
a) Truc
b) Fals return type.
with any
defined c)Maybe
A constructor is n o t d) Not sure
a) Trer
b) False constructors.

of
have all types c)Maybe
, Every
class must
d) Not sure
a) True
b) False class.
function ofa
member c)Maybe
c o n s t r u c t o r
is a
d) Not sure
A
a) True
b) False of a clase
data
members ass.
the
used to
initialize
c) Maybe
Constructor is d) Not sure
15.
a) True
b) False the class name
than
name
different

may
have c)Maybe
16. A
c o n s t r u c t o r

d) Not sure
a) True
b) False
after the class declaration
n.
defined
be
constructor is likely to c)Maybe
17. A
d) Not sure
a) True
b) False
functions from one object to another.
constructor copies Maybe
18. Copy
a) True d) Not sure
b) False
constructor?
about private
19. What is true instance ot a class exist
at any point oftin
a) Private
constructor ensures only one at any point of t
instances of a class exist
constructor ensures multiple
b) Private
the of a class. instantiation
Private constructor eases classes.
d) Private constructor allows creating objects in other

if this() and super() are used in a method.


20. What would be the behaviour
a) Runtime error Compile timeerror
b) Throws exception d) Runs successfully

21. What is false about constructor?


a) Constructors canrnot be synchronized in Java.
b) Java does not provide default
copy constructor.
) Constructor can have a returm
d) "this" and "super" can be type.
used in a constructor.
22. What is true ahout
a) Class.r1 ne' ren
Class.getlnstance()?
calls the constrctor
COMPUTER APPLICATIONS Question Bank - Class X
am18 ICSE Sem I & Il

1s same as new operator.


b) Class.getlnstance
cClass.getlnstance needs
to have matching constructor.
dClass.getlnstance creates object if class does not have any constructor.

about constructors?
23. What is true
a)lt can contain return type.

b) It take any number of parameters.


can

c)It can have any non-access modifiers.


d) Constructor cannot throw an exception.

24. Abstract class cannot have a constructor.


a) True c) Maybe
b) False d) Not sure

25. What is true about protected constructor?


a) Protected constructor can be called directly.
b) Protected constructor can only be called using super()
c)Protected constructor can be used outside package.
d) protected constructor can be instantiated even if child is in a different package.

26. What is not the use of "this" keyword in Java?


a) Passing itself to another method.
b) Calling another constructor in constructor chaining.
c)Referring to the instance variable when local variable has the same name.
d) Passing itself to method of the same class.

27. What would be the behaviour if one parameterized constructor is explicitly


defined?
a) Compilation error
b) Compilation will succeed
c)Runtimeerror
d) Compilation succeeds but at the time of creating object using default constructor, it
will throw compilation error

28. What would be the behaviour if a constructor has a return type?


a) Compilation error
b) Runtime error
c) Compilation and runs successfully
d) Only String return type is allowed

29. Predict the output?

package main;

class T
intt 20;
Exam18 ICSE Semi&

class Main
statie void main(String
args|)D
publ
T-newT0.
System out println(t1.t);

c)CompilerError
d) 5
a) 20
b) in Java?
constructors

about
is/are true
of the following
name.
class
hichConstructor name should
should be
besa
name
ter-less constructo
sameaas clasS, a default parameter-less
class,
constructor
a
default
parameter-less conet

Lonstructor
constructor
for a
lt you don't define a

automatically by the compiler.


created
and
i n i t i a l i z e s all
instance variables
to defau
calls super()
3. The defaultconstructor
value like 0, null. it m u s t be
called in first lineeof
af
constructor,
class
I f we want to call parent
constructor.
c)1,2 and 3
a) 1 d) 1,2, 3 and 4
b) 1,2

31. Is there any compiler error in the


below Java program?

class Point {
int m_x, m_y;
public Point(int x, int y) { mX =
X; m_y
=
y; }
public static void main(String argsl)

Point p = new Point();

a) Yes c)Maybe
b) No d) Not sure

32. Output of following Java programn


class Point
int m_, m_y

n i c ponis
Exami81CUL

{ this(10, 10);
public Point() return m_x; }
int getX() {
public return m_y; }|
getY() 1
public int
main(String args[]) {
static void
public Point();
= new
Point p
S y s t e m . o u t . p r i n t n ( p . g e t X ( ) ;

a) 10
c)compilererror
d) 5
b) 0

of a constructor inside a class should be


33. The placement
of class c) Anywhere in the class
a) Always at the beginning
at the end of class d) None
b) Always
is constructor is
34. The purpose of a Java
a) Initialization of variables with passed data
ult b) Writing custom code
c) Accepting other objects as inputs
d) All the above

the execution of_ is over in Java


35. Memory is allocated to an object once

language. c) destructor
a) main method
b) constructor d) None

arguments is called
36. In Java, a constructor with no parameters or

a) Default constructor
b) User-defined constructor

c) User- default constructor

d) Defined constructor

in adding more than


37. Overloading of constructors Java means

constructors with the different argument list.


a) 1
c3
d) 8
b) 2

with one or more arguments or parameters is called a


38. In Java, a constructor

a) Default constructor
or Non-default constructor
b) User-defined constructor

c)Jser-default
d) Non defined

45
Exam18ICSES e m l & | l i f it
c o n s t r u c t o r
to a class
no-argument

default
adds a
compiler at all.
39. The
c o m s t r u c t o r

deline a with
arguments

does not c o s d r u c t o r

a) one
at leasl
arguments
defimes with
b) constructors
c)defines many c o n s t r u c t o r
with n0
arguments

d)defines
one

constructor using the


overloaded
another
constructor
can call
40. A
keyword in Java. c) Con

d) this
a) super
b) local

with overloaded conos.

41. What is the output


of the below
public class Constructor3
Java program
structorg
int birds=10;
Constructor3()

this(20);

Constructor3(int birds)

System.out.println("Birds="+ birds);

public static void main(String[] args)

Constructor3 con =
new Constructor3();

a) Birds-0
b) Birds-10 c)Birds-20
d) Compiler error
42. In Java, you can pass variables from one constructor to another
overloaded constructor.
a) local variables
b)static variables c) non-static variables
d) local and static variables
43. Choose the correct
way of calling the second constructor
constructor in the below from the first
a) code options.
Constructor5()
int a=30;
this'A'
Examld

b) C o n s t r u c t o r 5 ( )

int a-30;

this('A ;
System.out.printn("Success");

Constructor5(char c)

c)
Constructor5()

this(A);
System.out.println("Success");

Constructor5(char c)

d) All the above

constructors?
44. What is the output of the below Java program with many
public class Constructor7

Constructor7(int a)

System.out.println("Book=" + a);

Constructor7(float a)

System.out.println(Pen="+ a );

public static void main(Stringll args)


new Constructor7(50.5f);
Constructor7 con =

c) Compiler error
a) Book=50
d) None of the above
b) Pen=50.5

constructors?
of the below Java program with many
45. What is the output
public class Constructor8

Constructor8(boolean a)

ystem.out.println("MODEM="+ a );
47
Class
-

Bank

estion
COMPUTER APPLICATIONS Qe
Exam18ICSESenm 1& 11

Constructor8(float a)
System.out.printn("ROUTER" a);

args)
void main(Stringl]
public static tructor8(50),
Constrt
new
Constructor8 con1 -

ConstructorQtra

new
Constructor8
con2

a ) R O U T E R - 5 0 . 0

MODEM-false

b)ROUTER-50

M O D E M = f a l s e

c) Compiler error w i t h ove


with
overloaded constructo
program

d) None
Java
b e l o w

ofthe
the outp
W h a t is
46. public class Giraffe

"Sugarcanes");
G i r a f f e ( i n ts u g a r c a n e s )

s u g a r c a n e s +

System.out.println("Eats "t
Giraffe(int age, int.sugarcanes)

S y s t e m . o u t . p r i n t l n ( " E a t s " +s u g a r c a n e s | 0 | + " S u g a r c a n e s " ) ;

main(Stringl]
args)
static
void
public
Giraffe(40);
new

Giraffe jiff2 Giraffe(5,10);

Giraffejiff=new

Sugarcanes
2.Eats 40
a)
2.Eats 10 Sugarcanes

1.Eats 40 Sugarcanes
b)
2.Eats 10 Sugarcanes
c)Compilererror
d) None time
at-

s o n s t r u c t o r
happens
uarinaded
Ton b a n k - Class X

*******

48. Java constructor overloading follows


program ming.
principle in Object-Oriented
a) inheritance
b) oncapsulation c)polymorphism
d) constructor
49. Java allows calling or invoking a method from a
a) True constructor.
b) False c)Maybe
d) Not sure
50. What is the output of the below
public class Constructor9
Java program?

Constructor9()
show);
void show()

System.out.println(JAM JAM");
public static void
main(Stringl) args)
Constructor9 con =new
Constructor9();
a) JAM JAM
b) No output c) Compiler error
d) None
b 44

5 b 25 b 45 a

6 a 26 d 46 b
7 27 d 47 b
b 28 a 48
9 b 29 a 49 a

10 C 30 d 50

11 a 31 a

12 a 32
13 b 33 C

14 a 34 d
15 a 35 b

16 b 36 a
17 b 37 a

18 b 38 b

19 a 39 a

20 C 40 d

You might also like