Computer Exam 18
Computer Exam 18
Solutions
b) Default constructor
c) Overloaded constructor
d) None of these
a) Temporary object
c) Both a and b
b)Anonymousobject
d) None of these
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.
Test)I1/| line 1
static void Test() { this(); } // ine 2
ine 3
public static void main(Stringl] args) { //
Test(;// line 4
a constructor
d) At line 4
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
about constructors?
23. What is true
a)lt can contain return type.
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
class Point {
int m_x, m_y;
public Point(int x, int y) { mX =
X; m_y
=
y; }
public static void main(String argsl)
a) Yes c)Maybe
b) No d) Not sure
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
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
d) Defined 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
d) this
a) super
b) local
this(20);
Constructor3(int birds)
System.out.println("Birds="+ birds);
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)
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 );
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
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)
main(Stringl]
args)
static
void
public
Giraffe(40);
new
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
*******
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