Sei sulla pagina 1di 13

MCQS

1. The default value of a static integer variable of a class in Java is,


(a) 0 (b) 1 (c) Garbage value (d) Null (e) -1.
A) a
2. Multiple inheritance means,
(a) more classes inheriting from one super class
(b) one class inheriting from more super classes
(c) more classes inheriting from more super classes
(d) None of the above

A) b
3. Which statement is not true in java language?
(a) A public member of a class can be accessed in all the packages.
(b) A private member of a class cannot be accessed by the methods of the same class.
(c) A private member of a class cannot be accessed from its derived class.
(d) A protected member of a class can be accessed from its derived class.
A) b
4. In java, Information hiding can be achieved through _______.
(a) Inheritance (b) Polymorphism (c) Encapsulation (d) All of above
A) c
5. In object-oriented programming, the technique by which subclass provides the
specific implementation of the method that has been provided by one of its parent
class is known as ________________.
(a) Constructor Overloading (b) Constructor Overriding (c) Method Overloading
(d) Method Overriding
A) d
6. The _______________ keyword can be used to reference a class’s hidden data fields.
(a) Super (b) extends (c) Final (d) this
A) d
7. To prevent any method from overriding, we declare the method as,
(a) static (b) private (c) final (d) all of the above.
A) d
8. Which one of the following is not true?
(a) A class containing abstract methods is called an abstract class.
(b) Abstract methods should be implemented in the derived class.
(c) An abstract class cannot have non-abstract methods.
(d) A class must be qualified as ‘abstract’ class, if it contains one abstract method.
(e) None of the above.
A) c
9. The fields in an interface are implicitly specified as,
(a) static only (b) protected (c) private (d) both static and final
A) d
10. What is the output of the following program:
public class testmeth
{
static int i = 1;
public static void main(String args[])
{
System.out.println(i+” , “);
m(i);
System.out.println(i);
}
public void m(int i)
{
i += 2;
}
}
(a) 1 , 3 (b) 3 , 1 (c) 1 , 1 (d) 1 , 0 (e) none of the above.
A) c
11. Which of the following is not true?
(a) An interface can extend another interface.
(b) A class which is implementing an interface must implement all the methods of the
interface.
(c) An interface can implement another interface.
(d) An interface is a solution for multiple inheritance in java.
(e) None of the above.
A) c
12. Which of the following is true?
(a) A finally block is executed before the catch block but after the try block.
(b) A finally block is executed, only after the catch block is executed.
(c) A finally block is executed whether an exception is thrown or not.
(d) A finally block is executed, only if an exception occurs.
(e) None of the above.
A) c
13. Which of these keywords must be used to handle the exception thrown by try
block?
A) try B) catch C) throw D) finally
A) b
14. Consider the two methods (within the same class)
public static int foo(int a, String s)
{
s = “Yellow”;
a=a+2;
return a;
}
public static void bar()
{
int a=3;
String s = “Blue”;
a = foo(a,s);
System.out.println(“a=”+a+” s=”+s);
}
public static void main(String args[])
{
bar();
}
What is printed on execution of these methods?
(a) a = 3 s = Blue (b) a = 5 s = Yellow (c) a = 3 s = Yellow
(d) a = 5 s = Blue (e) none of the above.
A) d
15. Which of the following variable declaration would NOT compile in a java
program?
(a) int var; (b) int VAR; (c) int var1; (d) int var_1; (e) int 1_var;.
A) e
16. Which of the following is TRUE?
(a) In java, an instance field declared public generates a compilation error.
(b) int is the name of a class available in the package java.lang
(c) Instance variable names may only contain letters and digits.
(d) A class has always a constructor (possibly automatically supplied by the java
compiler).
(e) The more comments in a program, the faster the program runs.
A) d
17. A constructor
(a) Must have the same name as the class it is declared within.
(b) Is used to create objects.
(c) May be declared private
(d) Both (A) and (B) above
(e) (a), (b) and (c) above.
A) e
18. Consider,
public class MyClass
{
public MyClass(){/code/}
// more code…
}
To instantiate MyClass, you would write?
(a) MyClass mc = new MyClass();
(b) MyClass mc = MyClass();
(c) MyClass mc = MyClass;
(d) MyClass mc = new MyClass;
(e) The constructor of MyClass should be defined as, public void MyClass(){/code/}.
A) a
19. Which is the container that contains title bar and Menu bars. It can also have
other components like buttons, text field etc.
(a) Panel
(b) Frame
(c)Window
A) b
20. In java AWT, object of _________________class is used to display a single line of
read only text.
(a) Textfield
(b) Label
(c)Textarea
(d) List
A) b
21. Subclass _____________ superclass in java.
A) extends

22. In method overloading, a method has different ________________ and same


_______________.
(a) Name, Parameters
(b) Parameters, Name
(c)Returntype, Parameters
(d) None
A) b
23. _______________ can be used to invoke the superclass’s methods and
constructors and can refer immediate parent class instance variables.
a. Final b. This
c. Super d. None of the mentioned
A) c
24. What is garbage collection in the context of Java?
(a) The operating system periodically deletes all the java files available on the system.
(b) Any package imported in a program and not used is automatically deleted.
(c) When all references to an object are gone, the memory used by the object is
automatically reclaimed.
(d) The JVM checks the output of any Java program and deletes anything that doesn’t
make sense.
(e) Janitors working for Sun Micro Systems are required to throw away any Microsoft
documentation found in the employees’ offices.
A) c
24) The java run time system automatically calls this method while garbage collection.
(a) finalizer() (b) finalize() (c) finally() (d) finalized()
A) b
25) The correct order of the declarations in a Java program is,
(a) Package declaration, import statement, class declaration
(b) Import statement, package declaration, class declaration
(c) Import statement, class declaration, package declaration
(d) Class declaration, import statement, package declaration
(e) Class declaration, package declaration, import statement.
A) a
26. A protected member can be accessed in,
(a) a subclass of the same package (b) a non-subclass of the same package
(c) a non-subclass of different package (d) a subclass of different package
(e) the same class.
Which is the false option?
A) c
27. What is the output of the following code:
class eq
{
public static void main(String args[])
{
String s1 = “Hello”;
String s2 = new String(s1);
System.out.println(s1==s2);
}
}
(a) true (b) false (c) 0 (d) 1 (e) Hello.
A) b
28. All exception types are subclasses of the built-in class
(a) Exception (b) RuntimeException (c) Error (d) Throwable
A) d
29. When an overridden method is called from within a subclass, it will always refer
to the version of that method defined by the
(a) Super class
(b) Subclass
(c) Compiler will choose randomly
(d) Interpreter will choose randomly
(e) None of the abvove.
A) b
30. In java, objects are passed as
(a) Copy of that object (b) Method called call by value (c) Memory address (d)
Constructor (e) Default constructor.
A) c
31. Which of the following is not a component of Java Integrated Development
Environment (IDE)?
(a) Net Beans (b) Borland’s Jbuilder (c) Symantec’s Visual Café (d) Microsoft Visual
Fox Pro (e) Microsoft Visual J++.
A) c
32. Members of a class specified as ……………….. are accessible only to methods of
that class.
(a) Protected (b) Final (c) Public (d) Private (e) Static.
A) d
33. Java compiler javac translates Java source code into ………………………
(a) Assembler language (b) Byte code (c) Bit code (d) Machine code
(e) Platform dependent code.
A) b
34. ……………….. are used to document a program and improve its readability.
(a) System cells (b) Keywords (c) Comments (d) Control structures (e) Blocks.
A) c
35, In Java, a try block should immediately be followed by one or more
……………….. blocks.
(a) Throw (b) Run (c) Exit (d) Catch (e) Error.
A) d
36. An abstract data type typically comprises a …………… and a set of ………………
respectively.
(a) Data representation, classes (b) Database, operations
(c) Data representation, objects (d) Control structure, operations
(e) Data representation, operations.
A) e
37. In object-oriented programming, the process by which one object acquires the
properties of another object is called
(a) Encapsulation (b) Polymorphism (c) Overloading
(d) Inheritance (e) Overriding.
A) d
38. In a class definition, the special method provided to be called to create an instance
of that class is known as a/an
(a) Interpreter (b) Destructor (c) Constructor (d) Object (e) Compiler.
A) c
39. Consider the following Java program :
public class Compute {
public static void main (string args [ ])
{
int result, x ;
x=1;
result = 0;
while (x < = 10) {
if (x%2 == 0) result + = x ;
++x;
}
System.out.println(result) ;
}
}
Which of the following will be the output of the above program?
(a) 55 (b) 30 (c) 25 (d) 35 (e) 45.
A) b
40. Consider the following code:
public class ClassA{
}
public class ClassB extends ClassA{
}
public class ClassC extends ClassB {
}
Type of inheritance is:
a.Multilevel Inheritance
b. Hierarchical Inheritance
c. Multiple Inheritance
d.Single Inheritance
Answer:
41. Making data fields private protects data and makes the class easy to
maintain. It is known as data field __________________.
a. Protection b. Abstraction
c. Construction d. Encapsulation
Answer: Encapsulation
42. In java, we can achieve multiple inheritance through
a) Encapsulation
b) Abstraction
c) Polymorphism
d) Interfaces
Answer: D
43. If array of objects is declared as given below, which is the limitation on objects?
Class_name arrayName[size];
a) The objects will have same values
b) The objects will not be initialized individually
c) The objects can never be initialized
d) The objects will have same data
Answer: B
44. Which variables are created when an object is created with the use of the keyword
'new' and destroyed when the object is destroyed?
a) Local variables
b) Class Variables
c) Instance variables
d) Static variables
Answer: c
45. Which one is a template for creating different objects?
a) An Array
b) A class
c) Interface
Answer: B
45. Which of the below method of String class is used to return char value for the
particular index?
a) char()
b) char charAt(int index)
c) charat()
d) Charat()
A) b
46. A getter method is also referred to _______________and a setter to
_______________.
(a) mutator, accessor (b) accessor, mutator (c) void get(),int set()
A) b
47. Java interface also represents _________________ relationship.
(a) IS-A (b) HAS-A (c) PART-OF (d) IS-A-KIND-OF
A) a
48. In interface, all the methods are _______________ by default.
(a) public, abstract (b) static, abstract (c) final, abstract (d) private, abstract
Answer: a
49. Can constructors be overloaded in derived class?
a) Yes, always
b) Yes, if derived class has no constructor
c) No, programmer can’t do it
d) No, never
Answer: D
50. Which among the following is false for a constructor?
a) Constructors doesn’t have a return value
b) Constructors are always user defined
c) Constructors are overloaded with different signature
d) Constructors may or may not have any arguments being accepted
Answer: B
True/False statements
1. A class declared as final cannot be inherited.
A) True
2. Objects of a subclass can be assigned to a super class reference.
A) True
3. An array in the Java programming language has the ability to store many different
types of values.
A) False
4. The break command is used to exit a loop.
a) True
5. Abstract class can’t be final in java.
A) True
6. Static methods can’t be made abstract in java.
A) True
7. If method parameters are declared final then the value of these parameters can be
changed.
A) False
8. Abstract class cannot provide the implementation of interface.
A) False
9. Every try statement should be followed by at least one catch statement.
A) True
8. An abstract class can be instantiated.
A) False
9. Inserting any value in the wrong index, results in Number Format Exception.
A) False
10. Objects of a subclass can be assigned to a super class reference.
A) True
11. Exception is an abnormal condition and cause abnormal termination of program.
A) True
12. The new operator dynamically allocates memory for an object.
A) True
13. Event Object is an object that receives the event.
A) False
14. The scope of instance and static variables is the entire class.
A) True
15. A composition is a type of relationship when one object owns other object
strongly.
A) True
Blanks
1. Association is a general binary relationship that describes an activity
between two classes.
2. Constants in a class are shared by all objects of the class.
3. In java, “this” is a Reference Variable that refers to the current object.
4. Aggregation is a weaker relationship between classes.
5. Abstraction is to ignore the inessential details, dealing instead with the
generalized, idealized model of the object.
6. Method overloading is an example of Static Polymorphism
7. A static/class variable is shared by all objects of the class.
8. Checked exception are also called as compile time exceptions.
9. Methods, variables and Constructors with private access modifier can only
be accessed within the declared class itself.
10.Every container in AWT has a method called add(Component c).
11.A method is used to expose the behavior of an object.
12.A default constructor is provided automatically only if no constructors are
explicitly defined in the class.
13.int length() method of class String is used to obtain length of String object.
14.super ( ) must always be the first statement executed inside a subclass
constructor.
15.A model is an abstraction of something real or conceptual.

Potrebbero piacerti anche