C++
Programming :: OOPS Concepts

Which of the
following type of class allows only one object of it to be created?
A. Virtual class
B. Abstract class
C. Singleton class
D. Friend class
Answer: Option C
Which of the
following is not a type of constructor?
A. Copy constructor
B. Friend constructor
C. Default constructor
D. Parameterized constructor
Answer: Option B
Which of the
following statements is correct?
A. Base class pointer cannot point to
derived class.
B. Derived class pointer cannot point to base
class.
C. Pointer to derived class cannot be
created.
D. Pointer to base class cannot be created.
Answer: Option B
Which of the
following is not the member of class?
A. Static function
B. Friend function
C. Const function
D. Virtual function
Answer: Option B
Which of the
following concepts means determining at runtime what method to invoke?
A. Data hiding
B. Dynamic Typing
C. Dynamic binding
D. Dynamic loading
Answer: Option C
Which of the
following term is used for a function defined inside a class?
A. Member Variable
B. Member function
C. Class function
D. Classic function
Answer: Option B
Which of the
following concept of oops allows compiler to insert arguments in a function
call if it is not specified?
A. Call by value
B. Call by reference
C. Default arguments
D. Call by pointer
Answer: Option C
How many instances of an abstract class can be created?
A. 1
B. 5
C. 13
D. 0
Answer: Option D
Which of the
following cannot be friend?
A. Function
B. Class
C. Object
D. Operator function
Answer: Option C
Which of the
following concepts of OOPS means exposing only necessary information to client?
A. Encapsulation
B. Abstraction
C. Data hiding
D. Data binding
Answer: Option C
Why reference is
not same as a pointer?
A. A reference can never be null.
B. A reference once established cannot be
changed.
C. Reference doesn't need an explicit
dereferencing mechanism.
D. All of the above.
Answer: Option D
cout is a/an
__________ .
A. operator
B. function
C. object
D. macro
Answer: Option C
Which of the
following concepts provides facility of using object of one class inside
another class?
A. Encapsulation
B. Abstraction
C. Composition
D. Inheritance
Answer: Option C
How many types
of polymorphisms are supported by C++?
A. 1
B. 2
C. 3
D. 4
Answer: Option B
Which of the
following is an abstract data type?
A. int
B. double
C. string
D. Class
Answer: Option D
Which of the
following concepts means adding new components to a program as it runs?
A. Data hiding
B. Dynamic typing
C. Dynamic binding
D. Dynamic loading
Answer: Option D
Which of the
following statement is correct?
A. A constructor is called at the time of
declaration of an object.
B. A constructor is called at the time of
use of an object.
C. A constructor is called at the time of
declaration of a class.
D. A constructor is called at the time of
use of a class.
Answer: Option A
Which of the
following correctly describes overloading of functions?
A. Virtual polymorphism
B. Transient polymorphism
C. Ad-hoc polymorphism
D. Pseudo polymorphism
Answer: Option C
Which of the
following approach is adapted by C++?
A. Top-down
B. Bottom-up
C. Right-left
D. Left-right
Answer: Option B
Which of the following is correct about function overloading?
A. The types of arguments are different.
B. The order of argument is different.
C. The number of argument is same.
D. Both A and B.
Answer: Option D
Which of the
following is correct about class and structure?
A. class can have member functions while
structure cannot.
B. class data members are public by default
while that of structure are private.
C. Pointer to structure or classes cannot
be declared.
D. class data members are private by
default while that of structure are public by default.
Answer: Option D
Which of the
following concepts means wrapping up of data and functions together?
A. Abstraction
B. Encapsulation
C. Inheritance
D. Polymorphism
Answer: Option B
Which of the following concepts means waiting until runtime to determine which function to call?
A. Data hiding
B. Dynamic casting
C. Dynamic binding
D. Dynamic loading
Answer: Option C
How "Late
binding" is implemented in C++?
A. Using C++ tables
B. Using Virtual tables
C. Using Indexed virtual tables
D. Using polymorphic tables
Answer: Option B
Which of the following
operator is overloaded for object cout?
A. >>
B. <<
C. +
D. =
Answer: Option B
Which of the
following is the correct class of the object cout?
A. iostream
B. istream
C. ostream
D. ifstream
Answer: Option C
Which of the
following cannot be used with the keyword virtual?
A. class
B. member functions
C. constructor
D. destructor
Answer: Option C
Which of the
following functions are performed by a constructor?
A. Construct a new class
B. Construct a new object
C. Construct a new function
D. Initialize objects
Answer: Option D
Which of the
following problem causes an exception?
A. Missing semicolon in statement in
main().
B. A problem in calling function.
C. A syntax error.
D. A run-time error.
Answer: Option D
Which one of the
following options is correct about the statement given below? The compiler
checks the type of reference in the object and not the type of object.
A. Inheritance
B. Polymorphism
C. Abstraction
D. Encapsulation
Answer: Option B
Which of the
following is the correct way of declaring a function as constant?
A. const int ShowData(void) { /* statements
*/ }
B. int const ShowData(void) { /* statements
*/ }
C. int ShowData(void) const { /* statements
*/ }
D. Both A and B
Answer: Option C
Which of the
following concepts is used to implement late binding?
A. Virtual function
B. Operator function
C. Const function
D. Static function
Answer: Option A
Which of the
following statement is correct?
A. C++ allows static type checking.
B. C++ allows dynamic type checking.
C. C++ allows static member function be of
type const.
D. Both A and B.
Answer: Option D
Which of the
following factors supports the statement that reusability is a desirable
feature of a language?
A. It decreases the testing time.
B. It lowers the maintenance cost.
C. It reduces the compilation time.
D. Both A and B.
Answer: Option D
Which of the
following ways are legal to access a class data member using this pointer?
A. this->x
B. this.x
C. *this.x
D. *this-x
Answer: Option A
Which of the
following is a mechanism of static polymorphism?
A. Operator overloading
B. Function overloading
C. Templates
D. All of the above
Answer: Option D
Which of the
following is correct about the statements given below?
I. All operators
can be overloaded in C++.
II. We can
change the basic meaning of an operator in C++.
A. Only I is true.
B. Both I and II are false.
C. Only II is true.
D. Both I and II are true.
Answer: Option B
What happens if
the base and derived class contains definition of a function with same prototype?
A. Compiler reports an error on
compilation.
B. Only base class function will get called
irrespective of object.
C. Only derived class function will get
called irrespective of object.
D. Base class object will call base class
function and derived class object will call derived class function.
Answer: Option D
Which of the
following are available only in the class hierarchy chain?
A. Public data members
B. Private data members
C. Protected data members
D. Member functions
Answer: Option C
Which of the
following is not a type of inheritance?
A. Multiple
B. Multilevel
C. Distributive
D. Hierarchical
Answer: Option C
Which of the
following operators cannot be overloaded?
A. []
B. ->
C. ?:
D. *
Answer: Option C
In which of the
following a virtual call is resolved at the time of compilation?
A. From inside the destructor.
B. From inside the constructor.
C. From inside the main().
D. Both A and B.
Answer: Option D
Which of the
following statements regarding inline functions is correct?
A. It speeds up execution.
B. It slows down execution.
C. It increases the code size.
D. Both A and C.
Answer: Option D
Which one of the
following is the correct way to declare a pure virtual function?
A. virtual void Display(void){0};
B. virtual void Display = 0;
C. virtual void Display(void) = 0;
D. void Display(void) = 0;
Answer: Option C
Which of the
following header file includes definition of cin and cout?
A. istream.h
B. ostream.h
C. iomanip.h
D. iostream.h
Answer: Option D
Which one of the
following options is correct?
A. Friend function can access public data
members of the class.
B. Friend function can access protected
data members of the class.
C. Friend function can access private data
members of the class.
D. All of the above.
Answer: Option D
Which of the following statements is correct in C++?
A. Classes cannot have data as protected
members.
B. Structures can have functions as
members.
C. Class members are public by default.
D. Structure members are private by
default.
Answer: Option B
Which of the
following is used to make an abstract class?
A. Declaring it abstract using static
keyword.
B. Declaring it abstract using virtual
keyword.
C. Making at least one member function as
virtual function.
D. Making at least one member function as
pure virtual function.
Answer: Option D
Which of the
following access specifier is used as a default in a class definition?
A. protected
B. public
C. private
D. friend
Answer: Option C
What is correct
about the static data member of a class?
A. A static member function can access only
static data members of a class.
B. A static data member is shared among all
the object of the class.
C. A static data member can be accessed
directly from main().
D. Both A and B.
Answer: Option D
Which of the
following provides a reuse mechanism?
A. Abstraction
B. Inheritance
C. Dynamic binding
D. Encapsulation
Answer: Option B
Which of the following statement is correct?
A. Class is an instance of object.
B. Object is an instance of a class.
C. Class is an instance of data type.
D. Object is an instance of data type.
Answer: Option B
Which of the
following operators cannot be overloaded?
A. []
B. ->
C. ?:
D. *
Answer: Option C
In which of the
following a virtual call is resolved at the time of compilation?
A. From inside the destructor.
B. From inside the constructor.
C. From inside the main().
D. Both A and B.
Answer: Option D
Which of the
following statements regarding inline functions is correct?
A. It speeds up execution.
B. It slows down execution.
C. It increases the code size.
D. Both A and C.
Answer: Option D
Which one of the
following is the correct way to declare a pure virtual function?
A. virtual void Display(void){0};
B. virtual void Display = 0;
C. virtual void Display(void) = 0;
D. void Display(void) = 0;
Answer: Option C
Which of the
following header file includes definition of cin and cout?
A. istream.h
B. ostream.h
C. iomanip.h
D. iostream.h
Answer: Option D
Java Questions
& Answers
Bitwise
Operators
Which of these
is not a bitwise operator?
a) &
b) &=
c) |=
d) <=
Answer: d
Which operator is used to invert all the
digits in a binary representation of a number?
a) ~
b) <<<
c) >>>
d) ^
Answer: a
On applying Left
shift operator, <<, on integer bits are lost one they are shifted past which
position bit?
a) 1
b) 32
c) 33
d) 31
Answer: d
Which right
shift operator preserves the sign of the value?
a) <<
b) >>
c) <<=
d) >>=
Answer: b
Which of these
statements are incorrect?
a) The left
shift operator, <<, shifts all of the bits in a value to the left
specified number of times
b) The right
shift operator, >>, shifts all of the bits in a value to the right
specified number of times
c) The left
shift operator can be used as an alternative to multiplying by 2
d) The right
shift operator automatically fills the higher order bits with 0
Answer: d
What is the
output of this program?
class bitwise_operator
{
public static void main(String args[])
{
int var1 = 42;
int var2 = ~var1;
System.out.print(var1 + "
" + var2);
}
}
a) 42 42
b) 43 43
c) 42 -43
d) 42 43
Answer: c
What is the output of this program?
class bitwise_operator
{
public static void main(String args[])
{
int a = 3;
int b = 6;
int c = a | b;
int d = a & b;
System.out.println(c + "
" + d);
}
}
a) 7 2
b) 7 7
c) 7 5
d) 5 2
Answer: a
What is the
output of this program?
class leftshift_operator
{
public static void main(String args[])
{
byte x = 64;
int i;
byte y;
i = x << 2;
y = (byte) (x << 2)
System.out.print(i + " "
+ y);
}
}
a) 0 64
b) 64 0
c) 0 256
d) 256 0
Answer: d
What is the
output of this program?
class rightshift_operator
{
public static void main(String args[])
{
int x;
x = 10;
x = x >> 1;
System.out.println(x);
}
}
a) 10
b) 5
c) 2
d) 20
What is the
output of this program?
class Output
{
public static void main(String args[])
{
int a = 1;
int b = 2;
int c = 3;
a |= 4;
b >>= 1;
c <<= 1;
a ^= c;
System.out.println(a + "
" + b + " " + c);
}
}
a) 3 1 6
b) 2 2 3
c) 2 3 4
d) 3 3 6
Answer: a
Relational Operators and Boolean Logic Operators:-
What is the
output of relational operators?
a) Integer
b) Boolean
c) Characters
d) Double
Answer: b
Which of these
is returned by “greater than”, “less than” and “equal to” operators?
a) Integers
b) Floating –
point numbers
c) Boolean
d) None of the
mentioned
Answer: c
Which of the
following operators can operate on a boolean variable?
1. &&
2. ==
3. ?:
4. +=
a) 3 & 2
b) 1 & 4
c) 1, 2 & 4
d) 1, 2 & 3
Answer: d
Explanation: Operator Short
circuit AND, &&, equal to, == , ternary if-then-else, ?:, are boolean
logical operators. += is an arithmetic operator it can operate only on numeric
values.
Which of these
operators can skip evaluating right hand operand?
a) !
b) |
c) &
d) &&
Answer: d
Which of these statements
is correct?
a) true and
false are numeric values 1 and 0
b) true and
false are numeric values 0 and 1
c) true is any
non zero value and false is 0
d) true and
false are non numeric values
Answer: d
What is the
output of this program?
class Relational_operator
{
public static void main(String args[])
{
int var1 = 5;
int var2 = 6;
System.out.print(var1 > var2);
}
}
a) 1
b) 0
c) true
d) false
Answer: d
What is the
output of this program?
class bool_operator
{
public static void main(String args[])
{
boolean a = true;
boolean b = !true;
boolean c = a | b;
boolean d = a & b;
boolean e = d ? b : c;
System.out.println(d + "
" + e);
}
}
a) false false
b) true ture
c) true false
d) false true
Answer: d
What is the
output of this program?
class ternary_operator
{
public static void main(String args[])
{
int x = 3;
int y = ~ x;
int z;
z = x > y ? x : y;
System.out.print(z);
}
}
a) 0
b) 1
c) 3
d) -4
Answer: c
What is the
output of this program?
class Output
{
public static void main(String args[])
{
int x , y = 1;
x = 10;
if (x != 10 && x / 0 == 0)
System.out.println(y);
else
System.out.println(++y);
}
}
a) 1
b) 2
c) Runtime error
owing to division by zero in if condition
d) Unpredictable
behavior of program
Answer: b
What is the
output of this program?
class Output
{
public static void main(String args[])
{
boolean a = true;
boolean b = false;
boolean c = a ^ b;
System.out.println(!c);
}
}
a) 0
b) 1
c) false
d) true
Answer: c
Concepts of OOPs
Which of the
following is not OOPS concept in Java?
a) Inheritance
b) Encapsulation
c) Polymorphism
d) Compilation
Answer: d
Which of the
following is a type of polymorphism in Java?
a) Compile time
polymorphism
b) Execution
time polymorphism
c) Multiple
polymorphism
d) Multilevel polymorphism
Answer: a
When does method
overloading is determined?
a) At run time
b) At compile
time
c) At coding
time
d) At execution
time
Answer: b
When Overloading
does not occur?
a) More than one
method with same name but different method signature and different number or
type of parameters
b) More than one
method with same name, same signature but different number of signature
c) More than one
method with same name, same signature, same number of parameters but different
type
d) More than one
method with same name, same number of parameters and type but different
signature
Answer: d
Which concept of
Java is a way of converting real world objects in terms of class?
a) Polymorphism
b) Encapsulation
c) Abstraction
d) Inheritance
Answer: c
Which concept of
Java is achieved by combining methods and attribute into a class?
a) Encapsulation
b) Inheritance
c) Polymorphism
d) Abstraction
Answer: a
What is it
called if an object has its own lifecycle and there is no owner?
a) Aggregation
b) Composition
c) Encapsulation
d) Association
Answer: d
What is it
called where child object gets killed if parent object is killed?
a) Aggregation
b) Composition
c) Encapsulation
d) Association
Answer: b
What is it
called where object has its own lifecycle and child object cannot belong to
another parent object?
a) Aggregation
b) Composition
c) Encapsulation
d) Association
Answer: a
Method
overriding is combination of inheritance and polymorphism?
a) True
b) false
Answer: a
JDK-JRE-JIT-JVM
Which component
is used to compile, debug and execute java program?
a) JVM
b) JDK
c) JIT
d) JRE
Answer: b
Which component
is responsible for converting bytecode into machine specific code?
a) JVM
b) JDK
c) JIT
d) JRE
Answer: a
Which component
is responsible to run java program?
a) JVM
b) JDK
c) JIT
d) JRE
Which component
is responsible to optimize bytecode to machine code?
a) JVM
b) JDK
c) JIT
d) JRE
Answer: c
Which statement
is true about java?
a) Platform
independent programming language
b) Platform
dependent programming language
c) Code
dependent programming language
d) Sequence
dependent programming language
Answer: a
Which of the
below is invalid identifier with the main method?
a) public
b) static
c) private
d) final
Answer: c
What is the
extension of java code files?
a) .class
b) .java
c) .txt
d) .js
Answer: b
Explanation:
Java files have .java extension.
What is the
extension of compiled java classes?
a) .class
b) .java
c) .txt
d) .js
Answer: a
How can we
identify whether a compilation unit is class or interface from a .class file?
a) Java source
file header
b) Extension of
compilation unit
c) We cannot
differentiate between class and interface
d) The class or
interface name should be postfixed with unit type
Answer: a
What is use of
interpreter?
a) They convert
bytecode to machine language code
b) They read
high level code and execute them
c) They are
intermediated between JIT and JVM
d) It is a
synonym for JIT
Answer: b
Constructors & Garbage Collection:-
What is the
return type of Constructors?
a) int
b) float
c) void
d) none of the
mentioned
Answer: d
Which keyword is
used by the method to refer to the object that invoked it?
a) import
b) catch
c) abstract
d) this
Answer: d
Which of the
following is a method having same name as that of its class?
a) finalize
b) delete
c) class
d) constructor
Answer: d
Which operator
is used by Java run time implementations to free the memory of an object when
it is no longer needed?
a) delete
b) free
c) new
d) none of the
mentioned
Answer: d
Which function
is used to perform some action when the object is to be destroyed?
a) finalize()
b) delete()
c) main()
d) none of the
mentioned
Answer: a
What is the
output of this program?
class box
{
int width;
int height;
int length;
int volume;
box()
{
width = 5;
height = 5;
length = 6;
}
void volume()
{
volume = width*height*length;
}
}
class constructor_output
{
public static void main(String args[])
{
box obj = new box();
obj.volume();
System.out.println(obj.volume);
}
}
a) 100
b) 150
c) 200
d) 250
Answer: b
What is the
output of this program?
class San
{
San()throws IOException
{
}
}
class Foundry
extends San
{
Foundry()
{
}
public static void main(String[]args)
{
}
}
a) compile time
error
b) run time
error
c) compile and
runs fine
d) unreported
exception java.io.IOException in default constructor
Answer: a
What is the
output of this program?
class box
{
int width;
int height;
int length;
int volume;
void finalize()
{
volume = width*height*length;
System.out.println(volume);
}
protected void volume()
{
volume = width*height*length;
System.out.println(volume);
}
}
class Output
{
public static void main(String args[])
{
box obj = new box();
obj.width=5;
obj.height=5;
obj.length=6;
obj.volume();
}
}
a) 150
b) 200
c) Run time
error
d) Compilation
error
Answer: a
Which of the
following statements are incorrect?
a) default
constructor is called at the time of object declaration
b) Constructor
can be parameterized
c) finalize()
method is called when a object goes out of scope and is no longer needed
d) finalize()
method must be declared protected
Answer: c
What is the
output of this program?
class area
{
int width;
int length;
int area;
void area(int width, int length)
{
this.width = width;
this.length = length;
}
}
class Output
{
public static void main(String args[])
{
area obj = new area();
obj.area(5 , 6);
System.out.println(obj.length +
" " + obj.width);
}
}
a) 0 0
b) 5 6
c) 6 5
d) 5 5
Answer: c
Constructor
What is true
about private constructor?
a) Private
constructor ensures only one instance of a class exist at any point of time
b) Private
constructor ensures multiple instances of a class exist at any point of time
c) Private
constructor eases the instantiation of a class
d) Private
constructor allows creating objects in other classes
Answer: a
What would be
the behaviour if this() and super() used in a method?
a) Runtime error
b) Throws exception
c) compile time
error
d) Runs
successfully
Answer: c
What is false
about constructor?
a) Constructors
cannot be synchronized in Java
b) Java does not
provide default copy constructor
c) Constructor
can be overloaded
d) “this” and
“super” can be used in a constructor
Answer: c
What is true
about Class.getInstance()?
a)
Class.getInstance calls the constructor
b)
Class.getInstance is same as new operator
c)
Class.getInstance needs to have matching constructor
d)
Class.getInstance creates object if class does not have any constructor
Answer: d
What is true
about constructor?
a) It can
contain return type
b) It can take
any number of parameters
c) It can have
any non access modifiers
d) Constructor
cannot throw an exception
Answer: b
Abstract class cannot
have a constructor.
a) True
b) False
Answer: b
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
Answer: b
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
Answer: d
What would be
the behaviour if one parameterized constructor is explicitly defined?
a) Compilation
error
b) Compilation
succeeds
c) Runtime error
d) Compilation
succeeds but at the time of creating object using default constructor, it
throws compilation error
Answer: d
What would be
behaviour if the constructor has a return type?
a) Compilation
error
b) Runtime error
c) Compilation
and runs successfully
d) Only String
return type is allowed
Answer: a
Overloading Methods & Argument Passing:-
What is the
process of defining two or more methods within same class that have same name
but different parameters declaration?
a) method
overloading
b) method
overriding
c) method hiding
d) none of the
mentioned
Answer: a
Which of these
can be overloaded?
a) Methods
b) Constructors
c) All of the
mentioned
d) None of the
mentioned
Answer: c
Which of these
is correct about passing an argument by call-by-value process?
a) Copy of
argument is made into the formal parameter of the subroutine
b) Reference to
original argument is passed to formal parameter of the subroutine
c) Copy of
argument is made into the formal parameter of the subroutine and changes made
on parameters of subroutine have effect on original argument
d) Reference to
original argument is passed to formal parameter of the subroutine and changes
made on parameters of subroutine have effect on original argument
Answer: a
What is the process
of defining a method in terms of itself, that is a method that calls itself?
a) Polymorphism
b) Abstraction
c) Encapsulation
d) Recursion
Answer: d
What is the
output of the following code?
class San
{
public void m1 (int i,float f)
{
System.out.println(" int float
method");
}
public void m1(float f,int i);
{
System.out.println("float int
method");
}
public static void main(String[]args)
{
San s=new San();
s.m1(20,20);
}
}
a) int float
method
b) float int
method
c) compile time
error
d) run time
error
Answer: c
What is the
output of this program?
class overload
{
int x;
int y;
void add(int a)
{
x =
a + 1;
}
void add(int a, int b)
{
x =
a + 2;
}
}
class Overload_methods
{
public static void main(String args[])
{
overload obj = new overload();
int a = 0;
obj.add(6);
System.out.println(obj.x);
}
}
a) 5
b) 6
c) 7
d) 8
Answer: c
What is the
output of this program?
class overload
{
int x;
int y;
void add(int a)
{
x =
a + 1;
}
void add(int a , int b)
{
x =
a + 2;
}
}
class Overload_methods
{
public static void main(String args[])
{
overload obj = new overload();
int a = 0;
obj.add(6, 7);
System.out.println(obj.x);
}
}
a) 6
b) 7
c) 8
d) 9
Answer: c
Method overriding
Which of this
keyword can be used in a subclass to call the constructor of superclass?
a) super
b) this
c) extent
d) extends
Answer: a
What is the
process of defining a method in a subclass having same name & type
signature as a method in its superclass?
a) Method
overloading
b) Method
overriding
c) Method hiding
d) None of the
mentioned
Answer: b
Which of these
keywords can be used to prevent Method overriding?
a) static
b) constant
c) protected
d) final
Answer: d
Which of these
is correct way of calling a constructor having no parameters, of superclass A
by subclass B?
a) super(void);
b)
superclass.();
c) super.A();
d) super();
Answer: d
At line number 2
below, choose 3 valid data-type attributes/qualifiers among “final, static,
native, public, private, abstract, protected”
public interface
Status
{
/* insert qualifier here */ int
MY_VALUE = 10;
}
a) final,
native, private
b) final,
static, protected
c) final,
private, abstract
d) final,
static, public
Answer: d
Explanation:
Every interface variable is implicitly public static and final.
6. Which of
these is supported by method overriding in Java?
a) Abstraction
b) Encapsulation
c) Polymorphism
d) None of the
mentioned
Answer: c
What is the
output of this program?
class Alligator
{
public static void main(String[] args)
{
int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};
int [][]y = x;
System.out.println(y[2][1]);
}
}
a) 2
b) 3
c) 7
d) Compilation
Error
Answer: c
What is the
output of this program?
advertisement
final class A
{
int i;
}
class B extends A
{
int j;
System.out.println(j + " " +
i);
}
class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.display();
}
}
a) 2 2
b) 3 3
c) Runtime Error
d) Compilation
Error
Answer: d
What is the
output of this program?
class Abc
{
public static void main(String[]args)
{
String[] elements = {
"for", "tea", "too" };
String first = (elements.length >
0) ? elements[0]: null;
}
}
a) Compilation
error
b) An exception
is thrown at run time
c) The variable
first is set to null
d) The variable
first is set to elements[0].
Answer: d
What is the
output of this program?
class A
{
int i;
public void display()
{
System.out.println(i);
}
}
class B extends A
{
int j;
public void display()
{
System.out.println(j);
}
}
class Dynamic_dispatch
{
public static void main(String args[])
{
B obj2 = new B();
obj2.i = 1;
obj2.j = 2;
A r;
r = obj2;
r.display();
}
}
a) 1
b) 2
c) 3
d) 4
Answer: b
The Object Class
Which of these
class is superclass of every class in Java?
a) String class
b) Object class
c) Abstract
class
d) ArrayList
class
Answer: b
Which of these
method of Object class can clone an object?
a) Objectcopy()
b) copy()
c) Object
clone()
d) clone()
Answer: c
Which of these
method of Object class is used to obtain class of an object at run time?
a) get()
b) void
getclass()
c) Class
getclass()
d) None of the
mentioned
Answer: c
Which of these
keywords can be used to prevent inheritance of a class?
a) super
b) constant
c) class
d) final
Answer: d
Which of these
keywords cannot be used for a class which has been declared final?
a) abstract
b) extends
c) abstract and
extends
d) none of the
mentioned
Answer: a
Which of these class
relies upon its subclasses for complete implementation of its methods?
a) Object class
b) abstract
class
c) ArrayList
class
d) None of the
mentioned
Answer: b
What is the
output of this program?
abstract class A
{
int i;
abstract void display();
}
class B extends A
{
int j;
void display()
{
System.out.println(j);
}
}
class Abstract_demo
{
public static void main(String args[])
{
B obj = new B();
obj.j=2;
obj.display();
}
}
a) 0
b) 2
c) Runtime Error
d) Compilation
Error
Answer: b
What is the
output of this program?
class A
{
int i;
int j;
A()
{
i = 1;
j = 2;
}
}
class Output
{
public static void main(String args[])
{
A obj1 = new A();
A obj2 = new A();
System.out.print(obj1.equals(obj2));
}
}
a) false
b) true
c) 1
d) Compilation
Error
Answer: a
What is the
output of this program?
class Output
{
public static void main(String args[])
{
Object obj = new Object();
System.out.print(obj.getclass());
}
}
a) Object
b) class Object
c) class
java.lang.Object
d) Compilation
Error
Answer: c
What is the
output of this program?
class A
{
int i;
int j;
A()
{
i = 1;
j = 2;
}
}
class Output
{
public static void main(String args[])
{
A obj1 = new A();
System.out.print(obj1.toString());
}
}
a) true
b) false
c) String
associated with obj1
d) Compilation
Error
Answer: c
Inheritance – Abstract Class and Super:-
Which of these
keywords are used to define an abstract class?
a) abst
b) abstract
c) Abstract
d) abstract
class
Answer: b
Which of these is not abstract?
a) Thread
b) AbstractList
c) List
d) None of the
Mentioned
Answer: a
If a class
inheriting an abstract class does not define all of its function then it will
be known as?
a) Abstract
b) A simple
class
c) Static class
d) None of the
mentioned
Answer: a
Which of these
is not a correct statement?
a) Every class
containing abstract method must be declared abstract
b) Abstract
class defines only the structure of the class not its implementation
c) Abstract
class can be initiated by new operator
d) Abstract
class can be inherited
Answer: c
Which of these
packages contains abstract keyword?
a) java.lang
b) java.util
c) java.io
d) java.system
Answer: a
What is the
output of this program?
class A
{
public int i;
private int j;
}
class B extends A
{
void display()
{
super.j = super.i + 1;
System.out.println(super.i + "
" + super.j);
}
}
class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
a) 2 2
b) 3 3
c) Runtime Error
d) Compilation
Error
Answer: d
What is the
output of this program?
class A
{
public int i;
public int j;
A()
{
i = 1;
j = 2;
}
}
class B extends A
{
int a;
B()
{
super();
}
}
class super_use
{
public static void main(String args[])
{
B obj = new B();
System.out.println(obj.i + "
" + obj.j)
}
}
a) 1 2
b) 2 1
c) Runtime Error
d) Compilation
Error
Answer: a
What is the
output of this program?
class A
{
int i;
void display()
{
System.out.println(i);
}
}
class B extends A
{
int j;
void display()
{
System.out.println(j);
}
}
class method_overriding
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
a) 0
b) 1
c) 2
d) Compilation
Error
Answer: c
What is the
output of this program?
class A
{
public int i;
protected int j;
}
class B extends A
{
int j;
void display()
{
super.j = 3;
System.out.println(i + "
" + j);
}
}
class Output
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
a) 1 2
b) 2 1
c) 1 3
d) 3 1
Answer: a
Inheritance – 1
Which of this keyword must be used to inherit
a class?
a) super
b) this
c) extent
d) extends
Answer: d
A class member
declared protected becomes a member of subclass of which type?
a) public member
b) private
member
c) protected
member
d) static member
Answer: b
Which of these
is correct way of inheriting class A by class B?
a) class B +
class A {}
b) class B
inherits class A {}
c) class B
extends A {}
d) class B
extends class A {}
Answer: c
Which two
classes use the Shape class correctly?
A. public class
Circle implements Shape
{
private int radius;
}
B. public
abstract class Circle extends Shape
{
private int radius;
}
C. public class
Circle extends Shape
{
private int radius;
public void draw();
}
D. public
abstract class Circle implements Shape
{
private int radius;
public void draw();
}
E. public class
Circle extends Shape
{
private int radius;
public void draw()
{
/* code here */
}
}
F. public
abstract class Circle implements Shape
{
private int radius;
public void draw()
{
/* code here */
}
}
a) B,E
b) A,C
c) C,E
d) T,H
Answer: a
What is the
output of this program?
class A
{
int i;
void display()
{
System.out.println(i);
}
}
class B extends A
{
int j;
void display()
{
System.out.println(j);
}
}
class inheritance_demo
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
a) 0
b) 1
c) 2
d) Compilation
Error
Answer: c
What is the output
of this program?
class A
{
int i;
}
class B extends A
{
int j;
void display()
{
super.i = j + 1;
System.out.println(j + "
" + i);
}
}
class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
a) 2 2
b) 3 3
c) 2 3
d) 3 2
Answer: c
What is the
output of this program?
class A
{
public int i;
public int j;
A()
{
i = 1;
j = 2;
}
}
class B extends A
{
int a;
B()
{
super();
}
}
class super_use
{
public static void main(String args[])
{
B obj = new B();
System.out.println(obj.i + "
" + obj.j)
}
}
a) 1 2
b) 2 1
c) Runtime Error
d) Compilation
Error
Answer: a
What is not type
of inheritance?
a) Single
inheritance
b) Double
inheritance
c) Hierarchical
inheritance
d) Multiple
inheritance
Answer: b
Using which of
the following, multiple inheritance in Java can be implemented?
a) Interfaces
b)
Multithreading
c) Protected
methods
d) Private
methods
Answer: a
All classes in
Java are inherited from which class?
a)
java.lang.class
b)
java.class.inherited
c)
java.class.object
d)
java.lang.Object
View Answer
Answer: d
In order to
restrict a variable of a class from inheriting to subclass, how variable should
be declared?
a) Protected
b) Private
c) Public
d) Static
Answer: b
If super class
and subclass have same variable name, which keyword should be used to use super
class?
a) super
b) this
c) upper
d) classname
Answer: a
Explanation:
Super keyword is used to access hidden super class variable in subclass.
6. Static
members are not inherited to subclass.
a) True
b) False
Answer: b
Which of the
following is used for implementing inheritance through an interface?
a) inherited
b) using
c) extends
d) implements
Answer: d
Which of the
following is used for implementing inheritance through class?
a) inherited
b) using
c) extends
d) implements
Answer: c
What would be
the result if a class extends two interfaces and both have a method with same
name and signature?
a) Runtime error
b) Compile time
error
c) Code runs
successfully
d) First called
method is executed successfully
Answer: b
Does Java
support multiple level inheritance?
a) True
b) False
Answer: a
Thread class
Which of these
method of Thread class is used to find out the priority given to a thread?
a) get()
b)
ThreadPriority()
c) getPriority()
d)
getThreadPriority()
Answer: c
Which of these
method of Thread class is used to Suspend a thread for a period of time?
a) sleep()
b) terminate()
c) suspend()
d) stop()
Answer: a
Which function of pre defined class Thread is
used to check weather current thread being checked is still running?
a) isAlive()
b) Join()
c) isRunning()
d) Alive()
Answer: a
What is the
output of this program?
class multithreaded_programing
{
public static void main(String args[])
{
Thread t = Thread.currentThread();
t.setName("New Thread");
System.out.println(t);
}
}
a)
Thread[5,main].
b) Thread[New
Thread,5].
c)
Thread[main,5,main].
d) Thread[New
Thread,5,main].
Answer: d
What is the
priority of the thread in output of this program?
class multithreaded_programing
{
public static void main(String args[])
{
Thread t = Thread.currentThread();
t.setName("New Thread");
System.out.println(t.getName());
}
}
a) main
b) Thread
c) New Thread
d) Thread[New
Thread,5,main].
Answer: c
What is the name
of the thread in output of this program?
advertisement
class multithreaded_programing
{
public static void main(String args[])
{
Thread t = Thread.currentThread();
System.out.println(t.getPriority());
}
}
a) 0
b) 1
c) 4
d) 5
Answer: d
What is the name
of the thread in output of this program?
class multithreaded_programing
{
public static void main(String args[])
{
Thread t = Thread.currentThread();
System.out.println(t.isAlive());
}
}
a) 0
b) 1
c) true
d) false
Answer: c
Packages
Which of these
keywords is used to define packages in Java?
a) pkg
b) Pkg
c) package
d) Package
Answer: c
Which of these
is a mechanism for naming and visibility control of a class and its content?
a) Object
b) Packages
c) Interfaces
d) None of the
Mentioned.
Answer: b
Which of this
access specifies can be used for a class so that its members can be accessed by
a different class in the same package?
a) Public
b) Protected
c) No Modifier
d) All of the
mentioned
Answer: d
Which of these
access specifiers can be used for a class so that its members can be accessed
by a different class in the different package?
a) Public
b) Protected
c) Private
d) No Modifier
Answer: a
Which of the
following is the correct way of importing an entire package ‘pkg’?
a) import pkg.
b) Import pkg.
c) import pkg.*
d) Import pkg.*
Answer: c
Which of the
following is an incorrect statement about packages?
a) Package
defines a namespace in which classes are stored
b) A package can
contain other package within it
c) Java uses
file system directories to store packages
d) A package can
be renamed without renaming the directory in which the classes are stored
Answer: d
Which of the
following package stores all the standard java classes?
a) lang
b) java
c) util
d) java.packages
Answer: b
What is the
output of this program?
package pkg;
class display
{
int x;
void show()
{
if (x > 1)
System.out.print(x + "
");
}
}
class packages
{
public static void main(String args[])
{
display[] arr=new display[3];
for(int i=0;i<3;i++)
arr[i]=new display();
arr[0].x = 0;
arr[1].x = 1;
arr[2].x = 2;
for (int i = 0; i < 3; ++i)
arr[i].show();
}
}
Note :
packages.class file is in directory pkg;
a) 0
b) 1
c) 2
d) 0 1 2
Answer: c
What is the
output of this program?
advertisement
package pkg;
class output
{
public static void main(String args[])
{
StringBuffer s1 = new
StringBuffer("Hello");
s1.setCharAt(1, x);
System.out.println(s1);
}
}
a) xello
b) xxxxx
c) Hxllo
d) Hexlo
Answer: c
What is the
output of this program?
package pkg;
class output
{
public static void main(String args[])
{
StringBuffer s1 = new
StringBuffer("Hello World");
s1.insert(6 , "Good ");
System.out.println(s1);
}
}
a)
HelloGoodWorld
b)
HellGoodoWorld
c) Compilation
error
d) Runtime error
Answer: d
Core Java API Packages
Which of these
package is used for graphical user interface?
a) java.applet
b) java.awt
c)
java.awt.image
d) java.io
Answer: b
Which of this
package is used for analyzing code during run-time?
a) java.applet
b) java.awt
c) java.io
d) java.lang.reflect
Answer: d
Which of this
package is used for handling security related issues in a program?
a) java.security
b)
java.lang.security
c)
java.awt.image
d)
java.io.security
Answer: a
Which of these
class allows us to get real time data about private and protected member of a
class?
a) java.io
b)
GetInformation
c)
ReflectPermission
d)
MembersPermission
Answer: c
Which of this
package is used for invoking a method remotely?
a) java.rmi
b) java.awt
c) java.util
d) java.applet
Answer: a
What is the output
of this program?
import java.lang.reflect.*;
class Additional_packages
{
public static void main(String args[])
{
try
{
Class c =
Class.forName("java.awt.Dimension");
Constructor constructors[] =
c.getConstructors();
for (int i = 0; i < constructors.length;
i++)
System.out.println(constructors[i]);
}
catch (Exception e)
{
System.out.print("Exception");
}
}
}
a) Program
prints all the constructors of ‘java.awt.Dimension’ package
b) Program
prints all the possible constructors of class ‘Class’
c) Program
prints “Exception”
d) Runtime Error
Answer: a
What is the
output of this program?
import java.lang.reflect.*;
class Additional_packages
{
public static void main(String args[])
{
try
{
Class c =
Class.forName("java.awt.Dimension");
Field fields[] = c.getFields();
for (int i = 0; i < fields.length; i++)
System.out.println(fields[i]);
}
catch (Exception e)
{
System.out.print("Exception");
}
}
}
a) Program
prints all the constructors of ‘java.awt.Dimension’ package
b) Program
prints all the methods of ‘java.awt.Dimension’ package
c) Program
prints all the data members of ‘java.awt.Dimension’ package
d) program
prints all the methods and data member of ‘java.awt.Dimension’ package
Answer: c
What is the
length of the application box made by this program?
import java.awt.*;
import java.applet.*;
public class myapplet extends Applet
{
Graphic g;
g.drawString("A Simple
Applet",20,20);
}
a) 20
b) Default value
c) Compilation
Error
d) Runtime Error
Answer: c
What is the
output of this program?
import java.lang.reflect.*;
class Additional_packages
{
public static void main(String args[])
{
try
{
Class c = Class.forName("java.awt.Dimension");
Method methods[] = c.getMethods();
for (int i = 0; i < methods.length; i++)
System.out.println(methods[i]);
}
catch (Exception e)
{
System.out.print("Exception");
}
}
}
a) Program
prints all the constructors of ‘java.awt.Dimension’ package
b) Program
prints all the methods of ‘java.awt.Dimension’ package
c) Program
prints all the data members of ‘java.awt.Dimension’ package
d) program
prints all the methods and data member of ‘java.awt.Dimension’ package
Answer: b
Writing Console Output
Which of these
class contains the methods print() & println()?
a) System
b) System.out
c)
BUfferedOutputStream
d) PrintStream
Answer: d
Which of these
methods can be used to writing console output?
a) print()
b) println()
c) write()
d) all of the
mentioned
Answer: d
Which of these
classes are used by character streams output operations?
a) InputStream
b) Writer
c) ReadStream
d)
InputOutputStream
Answer: b
Which of these class
is used to read from a file?
a) InputStream
b)
BufferedInputStream
c)
FileInputStream
d)
BufferedFileInputStream
Answer: c
What is the
output of this program?
class output
{
public static void main(String args[])
{
String a="hello i love
java";
System.out.println(indexof('i')+" "+indexof('o')+"
"+lastIndexof('i')+" "+lastIndexof('o') ));
}
}
a) 6 4 6 9
b) 5 4 5 9
c) 7 8 8 9
d) 4 3 6 9
Answer: a
What is the
output of this program?
class output
{
public static void main(String args[])
{
char c[]={'a','1','b',' ','A','0'];
for (int i = 0; i < 5; ++i)
{
if(Character.isDigit(c[i]))
System.out.println(c[i]" is a digit");
if(Character.isWhitespace(c[i]))
System.out.println(c[i]" is a Whitespace character");
if(Character.isUpperCase(c[i]))
System.out.println(c[i]"
is an Upper case Letter");
if(Character.isUpperCase(c[i]))
System.out.println(c[i]" is a lower case Letter");
i = i + 3;
}
}
}
a)
a is a lower case Letter
is White space character
b)
b is a lower case Letter
is White space characte
advertisement
c)
a is a lower case Letter
A is a upper case Letter
d)
a is a lower case Letter
0 is a digit
Answer: a
What is the
output of this program?
class output
{
public static void main(String args[])
{
StringBuffer s1 = new
StringBuffer("Hello");
StringBuffer s2 = s1.reverse();
System.out.println(s2);
}
}
a) Hello
b) olleH
c) HelloolleH
d) olleHHello
Answer: b
Reading Console Input
Which exception
is thrown by read() method?
a) IOException
b)
InterruptedException
c)
SystemException
d)
SystemInputException
Answer: a
Which of these
is used to read a string from the input stream?
a) get()
b) getLine()
c) read()
d) readLine()
Answer: c
Which of these
class is used to read characters and strings in Java from console?
a)
BufferedReader
b) StringReader
c)
BufferedStreamReader
d)
InputStreamReader
Answer: a
Which of these
class is implemented by FilterInputStream class?
a) InputStream
b)
InputOutputStream
c)
BufferedInputStream
d)
SequenceInputStream
Answer: a
What is the
output of this program if input given is “Hello stop World”?
class Input_Output
{
public static void main(String args[])
throws IOException
{
string str;
BufferedReader obj = new
BufferedReader(new InputStreamReader(System.in));
do
{
str = (char) obj.readLine();
System.out.print(str);
}
while(!str.equals("strong"));
}
}
a) Hello
b) Hello stop
c) World
d) Hello stop
World
Answer: d
What is the
output of this program?
class output
{
public static void main(String args[])
{
StringBuffer c = new
StringBuffer("Hello");
StringBuffer c1 = new
StringBuffer(" World");
c.append(c1);
System.out.println(c);
}
}
a) Hello
b) World
c) Helloworld
d) Hello World
Answer: d
What is the
output of this program?
advertisement
class output
{
public static void main(String args[])
{
StringBuffer s1 = new
StringBuffer("Hello");
s1.setCharAt(1,x);
System.out.println(s1);
}
}
a) xello
b) xxxxx
c) Hxllo
d) Hexlo
Answer: c
What is the
output of this program if input given is “abc’def/’egh”?
class Input_Output
{
public static void main(String args[])
throws IOException
{
char c;
BufferedReader obj = new
BufferedReader(new InputStreamReader(System.in));
do
{
c = (char) obj.read();
System.out.print(c);
} while(c != '\'');
}
}
a) abc’
b) abcdef/’
c) abc’def/’egh
d) abcqfghq
Answer: a
Throw, Throws & Nested Try
Which of these
keywords is used to generate an exception explicitly?
a) try
b) finally
c) throw
d) catch
Answer: c
Which of these
class is related to all the exceptions that are explicitly thrown?
a) Error
b) Exception
c) Throwable
d) Throw
Answer: c
Which of these
operator is used to generate an instance of an exception than can be thrown by
using throw?
a) new
b) malloc
c) alloc
d) thrown
Answer: a
Which of these
keywords is used to by the calling function to guard against the exception that
is thrown by called function?
a) try
b) throw
c) throws
d) catch
Answer: c
What is the
output of this program?
class exception_handling
{
public static void main(String args[])
{
try
{
int a = args.length;
int b = 10 / a;
System.out.print(a);
try
{
if (a == 1)
a = a / a - a;
if (a == 2)
{
int []c = {1};
c[8] = 9;
}
}
catch (ArrayIndexOutOfBoundException
e)
{
System.out.println("TypeA");
}
catch (ArithmeticException e)
{
System.out.println("TypeB");
}
}
}
}
a) TypeA
b) TypeB
c) Compile Time
Error
d) 0TypeB
Answer: c
What is the
output of this program?
class exception_handling
{
public static void main(String args[])
{
try
{
System.out.print("A");
throw new NullPointerException
("Hello");
}
catch(ArithmeticException e)
{
System.out.print("B");
}
}
}
a) A
b) B
c) Hello
d) Runtime
Exception
Answer: d
What is the
output of this program?
public class San
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally"
);
}
}
}
a) Finally
b) Compilation
fails
c) The code runs
with no output
d) An exception
is thrown at runtime
Answer: a
What is the
output of this program?
public class San
{
public static void main(String args[])
{
try
{
System.out.print("Hello world
");
}
finally
{
System.out.println("Finally
executing ");
}
}
}
a) The program
will not compile because no exceptions are specified
b) The program
will not compile because no catch clauses are specified
c) Hello world
d) Hello world
Finally executing
Answer: d
Multithreading
What requires
less resources?
a) Thread
b) Process
c) Thread and
Process
d) Neither
Thread nor Process
Answer: a
What does not
prevent JVM from terminating?
a) Process
b) Daemon Thread
c) User Thread
d) JVM Thread
Answer: b
What decides
thread priority?
a) Process
b) Process
scheduler
c) Thread
d) Thread
scheduler
Answer: d
What is true
about time slicing?
a) Time slicing
is OS service that allocates CPU time to available runnable thread
b) Time slicing
is the process to divide the available CPU time to available runnable thread
c) Time slicing
depends on its implementation in OS
d) Time slicing
allocates more resources to thread
Answer: b
Deadlock is a
situation when thread is waiting for other thread to release acquired object.
a) True
b) False
Answer: a
What should not
be done to avoid deadlock?
a) Avoid using
multiple threads
b) Avoid hold
several locks at once
c) Execute
foreign code while holding a lock
d) Use
interruptible locks
Answer: c
What is true
about threading?
a) run() method
calls start() method and runs the code
b) run() method
creates new thread
c) run() method
can be called directly without start() method being called
d) start()
method creates new thread and calls code written in run() method
Answer: d
Which of the
following is a correct constructor for thread?
a)
Thread(Runnable a, String str)
b) Thread(int
priority)
c)
Thread(Runnable a, int priority)
d)
Thread(Runnable a, ThreadGroup t)
Answer: a
Which of the
following stops execution of a thread?
a) Calling
SetPriority() method on a Thread object
b) Calling
notify() method on an object
c) Calling
wait() method on an object
d) Calling
read() method on an InputStream object
Answer: b
Which of the
following will ensure the thread will be in running state?
a) yield()
b) notify()
c) wait()
d)
Thread.killThread()
Answer: c
C#
Do While Loop Statements
Select output
for the following set of code :
static void Main(string[] args)
{
int i = 1, j = 2, k = 3;
do
{
Console.WriteLine((Convert.ToBoolean(Convert.ToInt32(i++))) &&
(Convert.ToBoolean(Convert.ToInt32(++j))));
}while (i <= 3);
Console.ReadLine();
}
a) 0 0 0
b) True True
True
c) 1 1 1
d) False False
False
View Answer
Answer: b
Explanation: 1
AND 1 = True.Similarly , non zero number || non zero number = True.
Output:
True True True.
2. Select output
for the following set of code :
static void
Main(string[] args)
{
float i = 1.0f, j = 0.05f;
do
{
Console.WriteLine(i++ - ++j);
}while (i < 2.0f && j <=
2.0f);
Console.ReadLine();
}
a) 0.05
b) -0.05
c) 0.95
d) -0.04999995
Answer: d
Output :
-0.04999995
3. Select the
output for the following code :
static void
Main(string[] args)
{
int i = 1, j = 5;
do
{
Console.WriteLine(i = i++ * j);
}while (i <= 10);
Console.ReadLine();
}
a) 5 10 15 20 25
30 35 40 45 50
b) 5 25
c) 5 11 16 21 26
31 36 41 46 51
d) 5 30
Answer: b
For the
incomplete program below, which of the code fragment will not result in an
infinite loop:
static void Main(string[] args)
{
int i = 1234 ,j = 0;
/*ADD CODE HERE */
Console.WriteLine(j);
}
a)
do
{
j = j + (i % 10);
}while ((i = i / 10)!= 0);
b)
do
{
j = j + (i % 10);
}while ((i / 10)!= 0);
c)
do
{
j = j + (i % 10);
}while ((i % 10)!= 0);
d)
do
{
j = j + (i % 10);
}while ((i/10 == 0)!= 0);
Answer: a
Select the output for the following set of code :
static void Main(string[] args)
{
long
x;
x = Convert.ToInt32(Console.ReadLine());
do
{
Console.WriteLine(x % 10);
}while ((x = x / 10) != 0);
Console.ReadLine();
}
enter x = 1234.
a) number of
digits present in x
b) prints ‘1’
c) prints
reverse of x
d) prints sum of
digits of ‘x’
Answer: c
Select output
for the following set of code :
static void Main(string[] args)
{
int i, s = 0, a = 1, d;
i = Convert.ToInt32(Console.ReadLine());
do
{
d = i % (2 * 4);
s = s + d * a;
}while ((Convert.ToInt32(i = i / (2 * 4)))
!= 0 && (Convert.ToBoolean(Convert.ToInt32((a) = (a * 10)))));
Console.WriteLine(s);
Console.ReadLine();
}
enter i = 342.
a) It finds
binary equivalent of i
b) It finds
octal equivalent of i
c) It finds sum
of digits of i
d) It finds
reverse of i
Answer: b
Correct syntax
for do while loop is :
a) do;
{
statement;
}while (condition);
b) do(condition)
{
statement;
}while;
c) do
{
statement;
}while (condition)
d) do
{
statement;
}while (condition);
Answer: d
Select the
output for the following set of code :
static void
Main(string[] args)
{
int x = 10;
do
{
Console.WriteLine( x++);
}
while(Convert.ToBoolean(5) &&
Convert.ToBoolean(4) && Convert.ToBoolean(3) &&
Convert.ToBoolean(2) && Convert.ToBoolean(1) &&
Convert.ToBoolean(0));
Console.ReadLine();
}
a) 13
b) 15
c) 11
d) 10
Answer: d
Select output for the following set of code
static void
Main(string[] args)
{
int x;
for (x = 10; x <= 15; x++)
while
(Convert.ToBoolean(Convert.ToInt32(x)))
{
do
{
Console.WriteLine(1);
if (Convert.ToBoolean(x >>
1))
continue;
}while (Convert.ToBoolean(0));
break;
}
Console.ReadLine();
}
a) 0 0
0….infinite times
b) 1 1
1….infinite times
c) 1 1 1 1 1 1
d) System
outofflow exception error
Answer: c
Select the
output for the following set of code :
static void
Main(string[] args)
{
int x = 0;
do
{
x++;
if (x == 5)
{
x++;
continue;
break;
}
Console.WriteLine(x + " ");
}
}while (x <
10);
a) 1 2 3 4 5
b) 10
c) 5 6 7 8 9 10
d) 1 2 3 4 5 6 7
8 9 10
Answer: d
Select the output for the following set of code :
static void
Main(string[] args)
{
int x;
for
(x = 1; x <= 3; x++)
{
int j = 1;
do
{
j++;
}while (x % j == 2);
Console.WriteLine(x + " " +
j);
}
Console.ReadLine();
}
a) 1 12 1 3 1
b) 1 12 13 1
c) 12 22 32
d) 11 21 31
Answer: c
Continue, Goto Statements
Select output for the following set of code :
static void Main(string[] args)
{
int i;
Console.WriteLine("enter value of
i:");
i = Convert.ToInt32(Console.ReadLine());
if (i < 7)
{
i++;
continue;
}
Console.WriteLine("final value of
i:" +i);
Console.ReadLine();
}
a) 12
b) 11
c) Compile time
error
d) 13
Answer: c
Select the output for the following set of Code :
static void Main(string[] args)
{
int i;
Console.WriteLine("enter value of
i:");
i = Convert.ToInt32(Console.ReadLine());
if ( i % 2 == 0)
goto even:
else
{
Console.WriteLine("number is
odd:");
Console.ReadLine();
}
even:
Console.WriteLine("number is even:");
Console.ReadLine();
}
for i = 4.
a) number is odd
b) number is
even
c) Compile time
error
d) none of the
mentioned
Answer: c
Select the output for the following set of code :
static void Main(string[] args)
{
int i = 1, j;
do
{
for (j = 1; ; j++)
{
if (j > 2)
break;
if (i == j)
continue;
Console.WriteLine(i + "
" + j);
}
i++;
} while (i < 3);
Console.ReadLine();
}
a) 1 2
2 1
b) 2 1
1 2
c) 1 3
2 1
d) 1 1
2 1
Answer: a
Select the
output for the following set of code :
static void Main(string[] args)
{
int i = 10 , j = 0;
label:
i--;
if ( i > 0)
{
Console.WriteLine(i+ " ");
goto label;
}
Console.ReadLine();
}
a) 1 2 3 4 5 6 7
8 9 10
b) 10 9 8 7 6 5
4 3 2 1 0
c) 9 8 7 6 5 4 3
2 1
d) 10 9 8 7 6 5
4 3 2 1
Answer: c
static void Main(string[] args)
{
int i = 0, j = 0;
while (i < 2)
{
l1: i--;
while (j < 2)
{
Console.WriteLine("hi\n");
goto l1;
}
}
Console.ReadLine();
}
a) hi hi hi
b) hi hi
c) hi
d) hi hi
hi…..infinite times
Answer: d
Select the
output for the following set of code :
static void Main(string[] args)
{
int i = 0;
if (i == 0)
{
goto label;
}
label: Console.WriteLine("HI...");
Console.ReadLine();
}
a) Hi…infinite
times
b) Code runs
prints nothing
c) Hi Hi
d) Hi…
Answer: d
Select the
output for the following set of code :
static void Main(string[] args)
{
int i = 0, j = 0;
l1: while (i < 2)
{
i++;
while (j < 3)
{
Console.WriteLine("loop\n");
goto l1;
}
}
Console.ReadLine();
}
a) loop is
printed infinite times
b) loop
c) loop loop
d) Compile time
error
Answer: c
Select output
for the following set of code :
static void Main(string[] args)
{
int i= 0,k;
label: Console.WriteLine(i);
if (i == 0)
goto label;
Console.ReadLine();
}
a) 0 0 0 0
b) 0 0 0
c) 0 infinite
times
d) 0
Answer: c
Select the
output for the following set of code :
static void Main(string[] args)
{
int i = 0;
int j = 0;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 3; j++)
{
if (i > 1)
continue;
Console.WriteLine("Hi
\n");
}
}
Console.ReadLine();
}
a) Prints hi 4
times
b) Prints hi 3
times
c) Prints hi 6
times
d) Prints hi
infinite times
Answer: c
Select the output for the following set of code :
static void Main(string[] args)
{
int a = 0;
int i = 0;
int b;
for (i = 0; i < 5; i++)
{
a++;
Console.WriteLine("Hello
\n");
continue;
}
Console.ReadLine();
}
a) print hello 4
times
b) print hello 3
times
c) print hello 5
times
d) print hello
infinite times
Answer: c
Select the output for the set of code:
static void Main(string[] args)
{
Console.WriteLine("HI");
continue;
Console.WriteLine("Hello");
Console.ReadLine();
}
a) Hi Hello
b) Hi
c) Hello
d) Compile time
error
Answer: d
Destructors in Class
Which operator
among the following signifies the destructor operator?
a) ::
b) :
c) ~
d) &
Answer: c
The method
called by clients of a class to explicitly release any resources like
network,connection,open files etc.When the object is no longer required?
a) Finalize()
b) End()
c) Dispose()
d) Close()
Answer: c
Name a method which
has the same name as that of class and which is used to destroy objects also
called automatically when application is finally on process of being getting
terminated.
a) Constructor
b) Finalize()
c) Destructor
d) End
Answer: c
Which of the
following statements are correct?
a) There is one
garbage collector per program running in memory
b) There is one
common garbage collector for all programs
c) To garbage
collect an object set all references to it as null
d) Both There is
one common garbage collector for all programs & To garbage collect an
object set all references to it as null
Answer: d
Operator used to
free the memory when memory is allocated ?
a) new
b) free
c) delete
d) none of the
mentioned
Answer: c
Select wrong
statement about destructor in C#?
a) A class can
have one destructor only
b) Destructors
cannot be inherited or overloaded
c) Destructors
can have modifiers or parameters
d) All of the
mentioned
Answer: c
Output from
following set of code ?
class sample
{
int i;
double k;
public sample (int ii, double kk)
{
i = ii;
k = kk;
double j = (i) + (k);
Console.WriteLine(j);
}
~sample()
{
double j = i - k;
Console.WriteLine(j);
}
}
class Program
{
static void Main(string[] args)
{
sample s = new sample(8, 2.5);
Console.ReadLine();
}
}
a) 0 0
b) 10.5 0
c) Compile time
error
d) 10.5 5.5
Answer: d
What is the
return type of destructor ?
a) int
b) void
c) float
d) none of the
mentioned
Answer: d
What is output
for the following set of Code ?
advertisement
class box
{
public int volume;
int width;
int height;
int length;
public box ( int w, int h, int l)
{
width = w;
height = h;
length = l;
}
public ~box()
{
volume = width * length * height;
}
}
class Program
{
static void Main(string[] args)
{
box b = new box(4, 5, 9);
Console.WriteLine(b.volume);
Console.ReadLine();
}
}
a) 0
b) 180
c) Compile time
error
d) None of the
mentioned
Answer: c
Output from
selective set of code is :
class box
{
public int volume;
int width;
int height;
int length;
public box ( int w, int h, int l)
{
this.width = w;
this.height = h;
this.length = l;
}
~ box()
{
volume = this.width * this.length *
this.height;
console.writeline(volume);
}
}
class Program
{
public
static void Main(string[] args)
{
box b = new box(4, 5, 9);
Console.ReadLine();
}
}
a) 0
b) Code executes
successfully but prints nothing
c) Compile time
error
d) 180
Answer: d
Polymorphism
The capability
of an object in Csharp to take number of different forms and hence display
behaviour as according is known as:
a) Encapsulation
b) Polymorphism
c) Abstraction
d) None of the
mentioned
Answer: b
Select the
output for the given set of code?
public class sample
{
public static int x = 100;
public static int y = 150;
}
public class newspaper :sample
{
new public static int x = 1000;
static void Main(string[] args)
{
console.writeline(sample.x +
" " + sample.y + " " + x);
}
}
a) 100 150 1000
b) 1000 150 1000
c) 100 150 1000
d) 100 150 100
Answer: c
Which of the
following keyword is used to change data and behavior of a base class by
replacing a member of the base class with a new derived member?
a) Overloads
b) Overrides
c) new
d) base
Answer: c
Correct way to
overload +operator?
a) public sample
operator + ( sample a, sample b)
b) public abstract
operator + (sample a,sample b)
c) public static
sample operator + (sample a, sample b)
d) All of the
mentioned
Answer: d
Correct
statement about C# code is?
public class maths
{
public int x;
public virtual void a()
{
}
}
public class subject : maths
{
new public void a()
{
}
}
a) The subject
class version of a() method gets called using sample class reference which
holds subject class object
b) subject class
hides a() method of base class
c) The code
replaces the subject class version of a() with its math class version
d) None of the
mentioned
Answer: d
Answer: b
Which of the
following statements is correct?
a) Each derived
class does not have its own version of a virtual method
b) If a derived
class does not have its own version of virtual method then one in base class is
used
c) By default
methods are virtual
d) All of the
mentioned
Answer: c
Selecting
appropriate method out of number of overloaded methods by matching arguments in
terms of number ,type and order and binding that selected method to object at
compile time is called?
a) Static
binding
b) Static
Linking
c) Compile time
polymorphism
d) All of the
mentioned
Answer: d
Wrong statement
about run time polymorphism is?
a) The
overridden base method should be virtual,abstract or override
b) An abstract
method is implicitly a virtual method
c) An abstract
inherited property cannot be overridden in a derived class
d) Both override
method and virtual method must have same access level modifier
Answer: c
Interfaces Introduction
Which statement
correctly defines Interfaces in C#.NET?
a) Interfaces
cannot be inherited
b) Interfaces
consists of data static in nature and static methods
c) Interfaces
consists of only method declaration
d) None of the mentioned
Answer: d
Which of the
following cannot be used to declare an interface correctly?
a) Properties
b) Methods
c) Structures
d) Events
Answer: c
A class consists
of two interfaces with each interface consisting of three methods.The class had
no instance data. Which of the following indicates the correct size of object
created from this class?
a) 12 bytes
b) 16 bytes
c) 0 bytes
d) 24 bytes
Answer: d
Which of the
following statements correctly define about the implementation of interface?
a) The calls to
implementation of interface methods are routed through a method table
b) A class which
implements an interface can explicitly implement members of that interface
c) One interface
can be implemented in another interface
d) None of the
mentioned
Answer: a
Select the
correct statement among the given statements?
a) One class
could implement only one interface
b) Properties
could be declared inside an interface
c) Interfaces
cannot be inherited
d) None of the
mentioned
Answer: b
Which keyword is
used for correct implementation of an interface in C#.NET?
a) interface
b) Interface
c) intf
d) Intf
Answer: a
Choose the
statements which makes interface different from classes?
a) Unlike
classes, interfaces consists of only declaration but not implementation
b) Interfaces
cannot be used directly like classes to create new objects
c) Interfaces
consists of declaration of methods,properties events and type definitions
d) All of the
mentioned
Answer: d
Which of the
following is the correct way of implementing an interface addition by class
maths?
a) class maths :
addition {}
b) class maths
implements addition {}
c) class maths
imports addition {}
d) none of the
mentioned
Answer: a
Does C#.NET
support partial implementation of interfaces?
a) True
b) False
c) Can’t Say
d) None of the
mentioned
Answer: b
Select the
correct implementation of the interface which is mentioned below.
interface a1
{
int fun(int i);
}
a)
class a
{
int fun(int i) as a1.fun
{
}
}
b)
class a:
implements a1
{
int
fun(int i)
{
}
}
c)
class a: a1
{
int a1.fun(int i)
{
}
}
d) None of the
mentioned
Answer: c
Which of these
can be used to fully abstract a class from its implementation?
a) Objects
b) Packages
c) Interfaces
d) None of the Mentioned
Answer: c
Access
specifiers which can be used for an interface are?
a) Public
b) Protected
c) Private
d) All of the
mentioned
Answer: a
Abstract Class & Methods
A type of class
which does not have its own objects but acts as a base class for its subclass
is known as?
a) Static class
b) Sealed class
c) Abstract
class
d) None of the
mentioned
Answer: c
The modifier
used to define a class which does not have objects of its own but acts as a
base class for its subclass is?
a) Sealed
b) Static
c) New
d) Abstract
Answer: d
Choose the
correct statements among the following:
a) An abstract
method does not have implementation
b) An abstract
method can take either static or virtual modifiers
c) An abstract
method can be declared only in abstract class
d) All of the
mentioned
Answer: d
What will be the
output for the given set of code?
namespace ConsoleApplication4
{
abstract class A
{
int i;
public
abstract void display();
}
class B: A
{
public
int j;
public override void display()
{
Console.WriteLine(j);
}
}
class Program
{
static void Main(string[] args)
{
B obj = new B();
obj.j = 2;
obj.display();
Console.ReadLine();
}
}
}
a) 0
b) 2
c) Compile time
error
d) 1
Answer: b
What will be the
output for the given set of code?
namespace ConsoleApplication4
{
abstract class A
{
public int i ;
public int j ;
public abstract void display();
}
class B: A
{
public int j = 5;
public override void display()
{
this.j = 3;
Console.WriteLine(i + " " + j);
}
}
class Program
{
static void Main(string[] args)
{
B obj = new B();
obj.i = 1;
obj.display();
Console.ReadLine();
}
}
}
a) 1, 5
b) 0, 5
c) 1, 0
d) 1, 3
Answer: d
What will be the
output for the given set of code?
namespace
ConsoleApplication4
{
abstract class A
{
public int i;
public abstract void display();
}
class B: A
{
public
int j;
public int sum;
public override void display()
{
sum = i + j;
Console.WriteLine(+i +
"\n" + +j);
Console.WriteLine("sum
is:" +sum);
}
}
class Program
{
static void Main(string[] args)
{
A obj = new B();
obj.i = 2;
B obj1 = new B();
obj1.j = 10;
obj.display();
Console.ReadLine();
}
}
}
a) 2, 10
12
b) 0, 10
10
c) 2, 0
2
d) 0, 0
0
Answer: c
If a class
inheriting an abstract class does not define all of its functions then it is
known as?
a) Abstract
b) A simple
class
c) Static class
d) None of the
mentioned
Answer: a
Which of the
following modifiers is used when an abstract method is redefined by a derived
class?
a) Overloads
b) Override
c) Base
d) Virtual
Answer: b
What will be the
output for the given set of code?
namespace
ConsoleApplication4
{
public abstract class A
{
public int i = 7;
public abstract void display();
}
class B: A
{
public int j;
public override void display()
{
Console.WriteLine(i);
Console.WriteLine(j);
}
}
class Program
{
static void Main(string[] args)
{
B obj = new B();
A obj1 = new B();
obj.j = 1;
obj1.i = 8;
obj.display();
Console.ReadLine();
}
}
}
a) 0, 8
b) 1, 8
c) 1, 7
d) 7, 1
Answer: d
What will be the
output for the given set of code?
namespace ConsoleApplication4
{
class A
{
public int i;
public void display()
{
Console.WriteLine(i);
}
}
class B: A
{
public int j;
public void display()
{
Console.WriteLine(j);
}
}
class Program
{
static void Main(string[] args)
{
B obj = new B();
obj.j = 1;
obj.i = 8;
obj.display();
Console.ReadLine();
}
}
}
a) 8, 1
b) 8
c) 1
d) 1, 8
Answer: c
Iterators
What is an
iterator?
a) a method
b) an operator
c) accessor
d) all of the
mentioned
Answer: d
What will be the
output of the given code snippet?
class MyClass
{
char[] chrs = { 'A', 'B', 'C', 'D' };
public System.Collections.IEnumerator
GetEnumerator()
{
foreach (char ch in chrs)
yield return ch;
}
}
class Program
{
static void Main(string[] args)
{
MyClass mc = new MyClass();
foreach (char ch in mc)
Console.Write(ch + " ");
Console.WriteLine();
Console.ReadLine();
}
}
a) Run time
error
b) Compile time
error
c) Code runs
successfully prints nothing
d) Code runs
successfully prints A, B, C, D
Answer: d
Choose the
correct statements about part of given code defined above?
public System.Collections.IEnumerator
GetEnumerator()
{
foreach (char ch in chrs)
yield return ch;
}
a) Definition of
iterator for MyClass
b) Implements
the GetEnumerator() method defined by IEnumerable
c) The yield
return statement returns the next object in the collection, which in this case
is the next character in chrs
d) All of the
mentioned
Answer: d
What does the
yield return statement specify in above code snippet?
a) returns the
output
b) returns the
next object in the collection
c) Both returns
the output & returns the next object in the collection
d) none of the
mentioned
Answer: b
What does the
given code snippet specify?
class MyClass
{
char chrs = 'A' ;
public IEnumerator GetEnumerator()
{
for (int i = 20; i >=0; --i)
yield return (char)((chrs + i));
}
}
class Program
{
static void Main(string[] args)
{
MyClass mc = new MyClass();
foreach (char ch in mc)
Console.Write(ch + " ");
Console.WriteLine();
Console.ReadLine();
}
}
a) A B C D E F G
H I J K L M N O P Q R S T U V
b) Run time
error
c) U T S R Q P O
N M L K J I H G F E D C B A
d) Compile
successfully prints nothing
Answer: c
What will the
given code snippet specify?
class MyClass
{
char chrs = 'A' ;
public IEnumerator GetEnumerator()
{
for (int i = 20; i >=0; --i)
if (i == 10) yield break;
yield return (char)((chrs + i));
}
}
class Program
{
static void Main(string[] args)
{
MyClass mc = new MyClass();
foreach (char ch in mc)
Console.Write(ch + " ");
Console.WriteLine();
Console.ReadLine();
}
}
a) Code run
successfully prints nothing
b) A B C D E F G
H I J K L M N O P Q R S T U V
c) U T S R Q P O
N M L
d) Compile time
error
Answer: c
Collection Classes
Which among the
following is not the ordered collection class?
a) BitArray
b) Queue
c) Stack
d) None of the
mentioned
Answer: a
Which among the
following is not an interface declared in System.Collection namespace?
a)
IDictionaryComparer
b) IEnumerable
c) IEnumerator
d) Icomparer
Answer: a
Which among the
following is the correct way to find out the number of elements currently present
in an ArrayListCollection called arr?
a) arr.Capacity
b) arr.Count
c) arr.MaxIndex
d)
arr.UpperBound
Answer: b
Which statement
is correct about the C#.NET code snippet given below?
Stack st = new
Stack();
st.Push("Csharp");
st.Push(7.3);
st.Push(8);
st.Push('b');
st.Push(true);
a) Unsimilar
elements like “Csharp”,7.3,8 cannot be stored in the same stack collection.
b) Boolean
values can never be stored in Stack collection
c) Perfectly
workable code
d) All of the
mentioned
Answer: c
Which is the correct
statement about an ArrayList collection that implements the IEnumerable
interface?
a) To access
members of ArrayList from the inner class, it is necessary to pass ArrayList
class reference to it
b) The inner
class of ArrayList can access ArrayList class members
c) The ArrayList
class consist of inner class that implements the IEnumerator interface
d) All of the
mentioned
Answer: d
Which among the
following is the correct way to access all the elements of the Stack collection
created using the C#.NET code snippet given below?
Stack st = new
Stack();
st.Push(10);
st.Push(20);
st.Push(-5);
st.Push(30);
st.Push(6);
a)
IEnumerable e;
e = st.GetEnumerator();
while (e.MoveNext())
Console.WriteLine(e.Current);
b)
IEnumerator e;
e = st.GetEnumerator();
while(e.MoveNext())
Console.WriteLine(e.Current);
c)
IEnumerable e;
e = st.GetEnumerable();
while(e.MoveNext())
Console.WriteLine(e.Current);
d) None of the
mentioned
Answer: b
The correct code
to access all the elements of the queue collection created using the C#.NET
code snippets given below is?
advertisement
Queue q = new
Queue();
q.Enqueue("Harsh");
q.Enqueue('a');
q.Enqueue(false);
q.Enqueue(70);
q.Enqueue(8.5);
a)
IEnumerator e;
e = q.GetEnumerator();
while(e.MoveNext())
Console.WriteLine(e.Current);
b)
IEnumerable e;
e = q.GetEnumerator();
while(e.MoveNext())
c)
IEnumerable e
e = q.GetEnumerable();
while(e.MoveNext())
Console.WriteLine(e.Current);
d) All of the
mentioned
Answer: a
Which statements
among the following are correct about the Collection Classes available in
Framework Class Library?
a) Elements of a
collection cannot be transmitted over a network
b) Elements
stored in a collection can be modified only if all the elements are of similar
types
c) Elements
stored in a Collection can be retrieved but cannot be modified
d) Collection
classes make use of efficient algorithms to manage the collection, hence
improving the performance of the program
Answer: d
Among the given
collections which one is I/O index based?
a) ArrayList
b) List
c) Stack
d) Queue
Answer: a
Which among the
given statements are correct about the Stack collection?
a) It can be
used for evaluation of expressions
b) It is used to
maintain a FIFO list
c) Top most
element of the Stack collection can be accessed using the Peek()
d) All of the
mentioned
Answer: d
Explanation:
None.
A HashTable t
maintains a collection of names of states and capital city of each state.Which
among the following finds out whether “New delhi” state is present in the
collection or not?
a)
t.HasValue("New delhi");
b)
t.ContainsKey("New
delhi");
c)
t.HasKey("New
delhi");
d)
t.ContainsValue("New
delhi");
Answer: b
In which of the
following collections is the I/O based on a key?
a) BitArray
b) SortedList
c) Queue
d) Stack
Answer: b
The wrong
statements about a HashTable collection are?
a) It is a keyed
collection
b) It is a
ordered collection
c) It’s not an
indexed collection
d) It implements
a IDictionaryEnumerator interface in its inner class
Answer: b
Multithreaded Programming
Which of these
keywords are used to implement synchronization?
a) synchronize
b) syn
c) synch
d) synchronized
Answer: d
Which keyword is
used for using the synchronization features defined by the Monitor class?
a) lock
b) synchronized
c) monitor
d) locked
Answer: a
What is
synchronization in reference to a thread?
a) It’s a
process of handling situations when two or more threads need access to a shared
resource
b) It’s a
process by which many threads are able to access the same shared resource
simultaneously
c) It’s a
process by which a method is able to access many different threads
simultaneously
d) It’s a method
that allows too many threads to access any information they require
Answer: a
Which method is
called when a thread is blocked from running temporarily?
a) Pulse()
b) PulseAll()
c) Wait()
d) Both Pulse()
& Wait()
Answer: c
What kind of
exception is being thrown if Wait(),Pulse() or PulseAll() is called from code
that is not within synchronized code?
a) System I/O
Exception
b) DivideByZero
Exception
c)
SynchronizationLockException
d) All of the
mentioned
Answer: c
What is mutex?
a) a mutually
exclusive synchronization object
b) can be
acquired by more than one thread at a time
c) helps in
sharing of resource which can be used by one thread
d) all of the
mentioned
Answer: a
What is
Semaphore?
a) Grant more
than one thread access to a shared resource at the same time
b) Useful when a
collection of resources is being synchronized
c) Make use of a
counter to control access to a shared resource
d) All of the
mentioned
Answer: d
Which method is
used to abort thread prior to it’s normal execution?
a) sleep()
b) terminate()
c) suspend()
d) Abort()
Answer: d
Which of these
statements is incorrect?
a) By
multithreading CPU idle time is minimized, and we can take maximum use of it
b) By
multitasking CPU idle time is minimized, and we can take maximum use of it
c) Two thread in
Csharp can have same priority
d) A thread can
exist only in two states, running and blocked
Answer: d
What is
multithreaded programming?
a) It’s a
process in which two different processes run simultaneously
b) It’s a
process in which two or more parts of same process run simultaneously
c) It’s a
process in which many different process are able to access same information
d) It’s a
process in which a single process can access information from many sources
Answer: b
Overloaded Operators
Which of the
following keyword is used to overload user defined types by defining static
member functions?
a) op
b) opoverload
c) operator
d)
operatoroverload
Answer: c
Which of
following statements are correct in nature?
a) The
conditional logical operators cannot be overloaded
b) The array
indexing operator can be overloaded
c) A public or
nested public preference type does not overload the equality operator
d) None of the
mentioned
Answer: a
Arrange the
following overloaded operators in increasing order of precedence?
%, <<, &, /, +
a) ‘%’ <
‘<<‘ < ‘+’ < ‘-‘ < ‘&’ < ‘/’
b) ‘<<‘
< ‘&’ < ‘%’ < ‘-‘ < ‘/’ < ‘+’
c) ‘&’ <
‘-‘ <‘%’ < ‘<<‘ < ‘/’ < ‘+’
d) ‘/’ < ‘-‘
< ‘%’ < ‘+’ < ‘<<‘ < ‘&’
Answer: b
Operators that
can be overloaded are?
a) ||
b) ‘+=’
c) +
d) [].
Answer: c
Which statements are correct about operator
overloading?
a) Mathematical
or physical modeling where we use classes to represent objects such as
vectors,matrices,complex-numbers etc
b) Graphical
programs where coordinate related objects are used to represent positions on
the screen
c) Financial
programs where a class represents an amount of money
d) All of the
mentioned
Answer: d
Correct way to
define operator method or to perform operator overloading is?
a) public static
op(arglist)
{
}
b) public static
retval op(arglist)
{
}
c) public static
retval operator op(arglist)
{
}
d) All of the
mentioned
Answer: c
Correct method
to define + operator is?
a) public sample
operator +(int a, int b)
b) public
abstract operator +(int a, int b)
c) public static
sample operator +(int a, int b)
d) public
abstract sample operator +(int a, int b)
Answer: c
Choose the
correct statement among the below mentioned statements:
a) Forgetting to
declare an operator method as public
b) Forgetting to
declare an operator method as static
c) Forgetting to
return a bool type value while overloading a relational operator
d) All of the
mentioned
Answer: d
What is vector
in operator overloading?
a) class
b) method()
c) data type
d) none of the
mentioned
Answer: c
Recursion
What is
Recursion in CSharp defined as?
a) Recursion is
another form of class
b) Recursion is
another process of defining a method that calls other methods repeatedly
c) Recursion is
a process of defining a method that calls itself repeatedly
d) Recursion is
a process of defining a method that calls other methods which in turn calls
this method
Answer: c
Which of these
will happen if recursive method does not have a base case?
a) Infinite loop
condition occurrence
b) System gets
hanged
c) After 10000
executions program will be automatically stopped
d) None of the
mentioned
Answer: a
Which of these
is not a correct statement?
a) A recursive
method must have a base case
b) Recursion
always uses stack
c) Recursion is
always managed by C# Runtime environment
d) Recursive
methods are faster that programmer written loop to call the function repeatedly
using a stack
Answer: c
What will be the
correct output for the given code snippet?
class recursion
{
int fact(int n)
{
int result;
if (n == 1)
return 1;
result = fact(n - 1) * n;
return result;
}
}
class Program
{
public static void main(String args[])
{
recursion obj = new recursion() ;
Console.WriteLine(obj.fact(4));
}
}
a) 24
b) 30
c) 120
d) 144
Answer: a
What will be the
correct output the for the given code snippet?
class maths
{
int fact(int n)
{
int result;
if (n == 1)
return 1;
result = fact(n - 1) * n;
return result;
}
}
class Output
{
static void main(String args[])
{
maths obj = new maths() ;
Console.WriteLine(obj.fact(1));
}
}
a) 2
b) 10
c) 1
d) 0
Answer: c
What will be the
correct output for the given code snippet?
class maths
{
int fact(int n)
{
int result;
if (n == 1)
return 1;
result = fact(n - 1) * n;
return result;
}
}
class Output
{
static void main(String args[])
{
maths obj = new maths() ;
Console.WriteLine(obj.fact(4)*obj.fact(2));
}
}
a) 64
b) 60
c) 120
d) 48
Answer: d
What will be the
correct output for the given code snippet?
class maths
{
int fact(int n)
{
int result;
if (n == 1)
return 1;
result = fact(n - 1) * n;
return result;
}
}
class Output
{
static void main(String args[])
{
maths obj = new maths() ;
Console.WriteLine(obj.fact(4)*(3));
}
}
a) 64
b) 60
c) 72
d) 84
Answer: c
Which of these
data types is used by operating system to manage the Recursion in Csharp?
a) Array
b) Queue
c) Tree
d) Stack
Answer: d
What will be the
output of the given code snippet?
class maths
{
public int fact(int n)
{
int result;
result = fact(n - 1) * n;
return result;
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths();
Console.WriteLine(obj.fact(4));
Console.ReadLine();
}
}
a) 24
b) 30
c) Compile time
error
d) Runtime Error
Answer: d
What will be the
correct output for the given code snippet?
class maths
{
public int fact(int n)
{
int result;
if (n == 2)
return 1;
result = fact(n - 1) * n;
return result;
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths();
Console.WriteLine(obj.fact(4));
Console.ReadLine();
}
}
a) 24
b) 0
c) 12
d) 1
Answer: c
Object Oriented in PHP
The practice of
separating the user from the true inner workings of an application through
well-known interfaces is known as _________
a) Polymorphism
b) Inheritance
c) Encapsulation
d) Abstraction
Answer: c
Which of the
following term originates from the Greek language that means “having multiple
forms,” defines OOP’s ability to redefine, a class’s characteristics?
a) Abstraction
b) Polymorphism
c) Inheritance
d) Differential
Answer: b
The practice of
creating objects based on predefined classes is often referred to as..
a) class
creation
b) object
creation
c) object
instantiation
d) class
instantiation
Answer: d
Which one of the
following property scopes is not supported by PHP?
a) friendly
b) final
c) public
d) static
Answer: a
Which one of the
following can be used to instantiate an object in PHP assuming class name to be
Foo?
a) $obj = new
$foo;
b) $obj = new
foo;
c) $obj = new
foo ();
d) obj = new foo
();
Answer: c
Which one of the
following is the right way to define a constant?
a) constant PI =
“3.1415”;
b) const $PI =
“3.1415”;
c) constant PI =
‘3.1415’;
d) const PI =
‘3.1415’;
Answer: d
Which one of the
following is the right way to call a class constant, given that the class is
mathFunction?
a) echo PI;
b) echo
mathFunction->PI;
c) echo
mathFunction::PI;
d) echo
mathFunction=PI;
Answer: c
Which one of the
following is the right way to invoke a method?
a)
$object->methodName();
b) object->methodName();
c)
object::methodName();
d)
$object::methodName();
Answer: a
Which of the
following is/are the right way to declare a method?
i) function
functionName() { function body }
ii) scope
function functionName() { function body }
iii) method
methodName() { method body }
iv) scope method
methodName() { method body }
a) Only ii)
b) Only iv)
c) i) and ii)
d) iii) and iv)
Answer: c
Which of the
following method scopes is/are not supported by PHP?
i) private
ii) final
iii) static
iv) abstract
a) Only ii)
b) Only iv)
c) ii) and iv)
d) None of the
mentioned
Answer: d
Which method
scope prevents a method from being overridden by a subclass?
a) Abstract
b) Protected
c) Final
d) Static
Answer: c
Which of the
following statements is/are true about Constructors in PHP?
i) PHP 4
introduced class constructors.
ii) Constructors
can accept parameters.
iii)
Constructors can call class methods or other functions.
iv) Class
constructors can call on other constructors.
a) ii) and iii)
b) All of the
mentioned
c) None of the
mentioned
d) ii), iii) and
iv)
Answer: b
PHP recognizes
constructors by the name_________
a) classname()
b) _construct()
c) function
_construct()
d) function
__construct()
Answer: d
Which version of
PHP introduced the instanceof keyword?
a) PHP 4
b) PHP 5
c) PHP 5.3
d) PHP 6
Answer: b
Which one of the
following functions is used to determine whether a class exists?
a) exist()
b) exist_class()
c) class_exist()
d) __exist()
Answer: c
Which one of the
following functions is used to determine object type?
a) obj_type()
b) type()
c) is_a()
d) is_obj()
Answer: c
Which one of the
following keyword is used to inherit our subclass into a superclass?
a) extends
b) implements
c) inherit
d) include
Answer: a
In the PHP code
given below, what is/are the properties?
<?php
class Example
{
public $name;
function Sample()
{
echo "This is an
example";
}
}
?>
a) echo “This is
an example”;
b) public $name;
c) class Example
d) function sample()
Answer: b
Which keyword is
used to refer to properties or methods within the class itself?
a) private
b) public
c) protected
d) $this
Answer: d
Which keyword
allows class members (methods and properties) to be used without needing to
instantiate a new instance of the class?
a) protected
b) final
c) static
d) private
Answer: c
0 মন্তব্যসমূহ