Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
Midterm Revision
1. Which feature of OOPS described the reusability of code?
a. Abstraction
b. Encapsulation
c.
Polymorphism
d. Inheritance
2. Which feature of OOPS derives the class from another class?
a. Inheritance
b. Data hiding
c.
Encapsulation
d. Polymorphism
3. Which among the following cannot be used for the concept of polymorphism?
a. Static member function
b. Constructor Overloading
c.
Member function overloading
d. Method overriding
4. Which function best describes the concept of polymorphism in programming languages?
a. Class member function
b. Virtual function
c.
Inline function
d. Undefined function
5. Which member of the superclass is never accessible to the subclass?
a. Public member
b. Protected member
c.
Private member
d. All of the mentioned
6. Which class cannot create its instance?
a. Parent class
b. Nested class
c.
Anonymous class
d. Abstract class
7. Which definition best defines the concept of abstraction?
a. Hides the important data
b. Hides the implementation and showing only the features
c.
1
Hiding the implementation
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
d. Showing the important data
8.
Method overriding is a combination of inheritance and polymorphism?
a. True
b. False
9.
What is it called where a child object gets killed if the parent object is killed?
a. Aggregation
b. Composition
c.
Encapsulation
d. Association
10. When does method overloading is determined?
a.
At run time
b. At compile time
c.
At coding time
d. At execution time
11. Which of the following is a type of polymorphism in Java?
a. Compile time polymorphism
b. Multiple polymorphism
c.
Multilevel polymorphism
12. Which of the following is not an OOP concept in Java?
a. Inheritance
b. Encapsulation
c.
Polymorphism
d. Compilation
13. Which of the below is invalid identifier with the main method?
a. public
b. static
c.
private
d. final
14. What is the extension of java code files?
a. .class
b. .java
c.
.txt
d. .js
15. What is the extension of compiled java classes?
a. .class
b. .java
c.
2
.txt
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
d. .js
16. What is stored in the object obj in the following lines of Java code?
box obj;
a. Memory address of allocated memory of object
b. NULL
c.
Any arbitrary pointer
d. Garbage
17. Which of the following is a valid declaration of an object of class Box?
a. Box obj = new Box();
b. Box obj = new Box;
c.
obj = new Box();
d. new Box obj;
18. Which of these statements is incorrect?
a. Every class must contain a main() method
b. There can be only one main() method in a program
c. main() method must be made public
19. What will be the output of the following Java program?
1.
class main_class
2.
{
3.
public static void main(String args[])
4.
{
5.
int x = 9;
6.
if (x == 9)
7.
{
8.
int x = 8;
9.
System.out.println(x);
10.
}
11.
}
12.
}
a. 9
b. 8
c.
Compilation error
d. Runtime error
20. Which of the following statements is correct?
a. Protected method is accessible to all other classes in the hierarchy
b. Protected method is accessible only to subclasses of its parent class
c.
Protected method can only be called by object of its class
d. Protected method is accessible to subclasses of its parent class and any other class in
the same package
3
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
21. What will be the output of the following Java program?
1.
class box
2.
{
3.
int width;
4.
int height;
5.
int length;
6.
}
7.
class mainclass
8.
{
9.
public static void main(String args[])
10.
{
11.
box obj = new box();
12.
Obj.width = 3;
13.
Obj.height = 4;
14.
Obj.length = 5;
15.
System.out.println(obj);
16.
}
17.
}
a. 0
b. { width = 3, height = 4, length = 5 }
c.
Runtime error
d. classname@hashcode in hexadecimal form
22. What will be the output of the following Java program?
1.
class variable_scope
2.
{
3.
public static void main(String args[])
4.
{
5.
int x;
6.
x = 5;
7.
{
8.
int y = 6;
9.
System.out.print(x + " " + y);
10.
}
11.
System.out.println(x + " " + y);
12.
}
13.
}
a. Compilation error
b. Runtime error
c. 5 6 5 6
d. 5 6 5
23. What will be the output of the following Java program?
1. 24
class output
2.
{
3.
public static void main(String args[])
4.
{
5.
StringBuffer s1 = new StringBuffer("Quiz");
6.
StringBuffer s2 = s1.reverse();
7.
System.out.println(s2);
8.
}
9.
}
4
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
a. QuizziuQ
b. ziuQQuiz
c. Quiz
d. ziuQ
24. Which of the following is a superclass of every class in Java?
a. ArrayList
b. Abstract class
c. Object class
d. String
25. What will be the output of the following Java code?
1.
class Output
2.
{
3.
public static void main(String args[])
4.
{
5.
double x = 3.14;
6.
int y = (int) Math.ceil(x);
7.
System.out.print(y);
8.
}
9.
}
a. 3
b. 0
c. 4
d. 3.0
e. 4.0
26. Which of these keywords are used for the block to be examined for exceptions?
a. check
b. throw
c. catch
d. try
27. What will be the output of the following Java program?
1.
final class A
2.
{
3.
int i;
4.
}
5.
class B extends A
6.
{
7.
int j;
8.
System.out.println(j + " " + i);
9.
}
10.
class inheritance
11.
{
12.
public static void main(String args[])
13.
{
14.
B obj = new B();
15.
obj.display();
16.
}
17. }
a. 2 2
b. 3 3
c. Runtime Error
d. Compilation Error
28. Which of these is an incorrect array declaration?
5
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
a. int arr[] = new int[5]
b. int [] arr = new int[5]
c. int arr[] = new int[5]
d. int arr[] = int [5] new
29. What will be the output of the following Java code?
int arr[] = new int [5];
System.out.print(arr)
a. 0
b. value stored in arr[0]
c. 00000
d. Class name@ hashcode in hexadecimal form
30. Which of these is an incorrect Statement?
a. It is necessary to use new operator to initialize an array
b. Array can be initialized using comma separated expressions surrounded by curly braces
c. Array can be initialized when they are declared
d. None of the mentioned
31. What is the type of variable ‘b’ and ‘d’ in the following Java snippet?
int a[], b;
int []c, d;
a. ‘b’ and ‘d’ are int
b. ‘b’ and ‘d’ are arrays of type int
c. ‘b’ is int variable; ‘d’ is int array
d. ‘d’ is int variable; ‘b’ is int array
32. What will be the output of the following Java code snippet?
1. Object[] names = new String[3];
2. names[0] = new Integer(0);
a. ArrayIndexOutOfBoundsException
b. ArrayStoreException
c. Compilation Error
d. Code runs successfully
33. What is the process of defining more than one method in a class differentiated by method
signature?
a. Function overriding
b. Function overloading
c. Function doubling
d. None of the mentioned
34. Which of the following is a method having the same name as that of its class?
a. Abstract method
b. Final method
c. Constructor
d. Static method
35. Which method can be defined only once in a program?
6
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
a. Final method
b. Main method
c. Static method
d. Abstract method
36. What will be the output of the following Java program?
1.
class box
2.
{
3.
int width;
4.
int height;
5.
int length;
6.
int volume;
7.
void volume(int height, int length, int width)
8.
{
9.
volume = width*height*length;
10.
}
11.
}
12.
class Prameterized_method
13.
{
14.
public static void main(String args[])
15.
{
16.
box obj = new box();
17.
obj.height = 1;
18.
obj.length = 5;
19.
obj.width = 5;
20.
obj.volume(3,2,1);
21.
System.out.println(obj.volume);
22.
}
23.
}
a. 0
b. Compile error
c. 25
d. 6
37. What will be the output of the following Java program?
24.
class box
25.
{
26.
int width;
27.
int height;
28.
int length;
29.
int volume;
30.
void volume()
31.
{
32.
volume = width*height*length;
33.
}
34.
}
35.
class Prameterized_method
36.
{
37.
public static void main(String args[])
38.
{
39.
box obj = new box();
40.
obj.height = 1;
41.
obj.length = 5;
42.
obj.width = 5;
7
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
43.
44.
45.
46.
obj.volume();
System.out.println(obj.volume);
}
}
a. 0
b. Compile error
c. 25
d. 6
38. What is the return type of Constructors?
a. Int
b. Void
c. String
d. Can be any type
e. None of the mentioned
39. Which keyword is used by the method to refer to the object that invoked it?
a. import
b. catch
c. abstract
d. this
40. 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
41. Constructors can be private
a. True
b. False
42. Classes can be private
a. True
b. False
43. What is false about constructor?
a. Compiler creates an empty argument constructor if you don’t write one
b. Java does not provide default copy constructor
c. Constructor can have a return type
d. “this” or “super” can be used in a constructor
44. Abstract class can have a constructor.
a. True
b. False
45. Which of these can be overloaded?
a. Methods
b. Constructors
c. All of the mentioned
d. None of the mentioned
46. What will be the output of the following Java code?
1. class San
2. {
3. public void m1 (int i,float f)
4. {
5. System.out.println(" int float method");
6. }
8
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
7.
8. public void m1(float f,int i);
9. {
10. System.out.println("float int method");
11. }
12.
13. public static void main(String[]args)
14. {
15.
San s=new San();
16.
s.m1(20,20);
17. }
18.}
a. int float method
b. float int method
c. compile time error
d. run time error
47. Which of these access specifiers must be used for the main() method?
a. private
b. public
c. protected
d. none of the mentioned
48. Which of these is used to access a member of class before the object of that class is
created?
a. public
b. private
c. static
d. protected
49. Which of these is used as a default for a member of a class if no access specifier is used
for it?
a. private
b. public
c. public, within its own package
d. protected
50. What is the process by which we can control what parts of a program can access the
members of a class?
a. Polymorphism
b. Abstraction
c. Encapsulation
d. Recursion
51. Which one of the following is not an access modifier?
a. Public
b. Private
c. Protected
d. Void
52. All the variables of class should be ideally declared as?
a. private
b. public
c. protected
d. default
53. Which of the following modifiers means a particular variable cannot be accessed within
the package?
9
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
a. private
b. public
c. protected
d. default
54. How can a protected modifier be accessed?
a. accessible only within the class
b. accessible only within package
c. accessible within package and outside the package but through inheritance only
d. accessible by all
55. What happens if the constructor of class A is made private?
a. Any class can instantiate objects of class A
b. Objects of class A can be instantiated only within the class where it is declared
c. Inherited class can instantiate objects of class A
d. classes within the same package as class A can instantiate objects of class A
56. All the variables of interface should be?
a. default and final
b. default and static
c. public, static and final
d. protect, static and final
57. What is true of final class?
a. Final class cause compilation failure
b. Final class cannot be instantiated
c. Final class cause runtime failure
d. Final class cannot be inherited
58. How many copies of static and instance variables are created when 10 objects are created
of a class?
a. 1, 10
b. 10, 10
c. 10, 1
d. 1, 1
59. Can a class be declared with a protected modifier.
a. True
b. False
60. Which is the modifier when there is none mentioned explicitly?
a. protected
b. private
c. public
d. default
61. Which of these keywords is used to prevent content of a variable from being modified?
a. final
b. last
c. constant
d. static
62. Which of the following statements are incorrect?
a. static methods can call other static methods only
b. static methods must only access static data
c. static methods can not refer to this or super in any way
d. when object of class is declared, each object contains its own copy of static variables
63. String in Java is a?
a. class
b. object
10
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
c. variable
d. character array
64. Which of the following statements are incorrect?
a. String is a class
b. Strings in java are mutable
c. Every string is an object of class String
d. Java defines a peer class of String, called StringBuffer, which allows string to be altered
65. Which of these keywords can be used in a subclass to call the constructor of superclass?
a. super
b. this
c. extent
d. extends
66. What is the process of defining a method in a subclass having the same name & type
signature as a method in its superclass?
a. Method overloading
b. Method overriding
c. Method hiding
d. None of the mentioned
67. Which of these keywords can be used to prevent Method overriding?
a. static
b. constant
c. protected
d. final
68. Which of these is the 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();
69. Which of these is supported by method overriding in Java?
a. Abstraction
b. Encapsulation
c. Polymorphism
d. None of the mentioned
70. Using which of the following, multiple inheritance in Java can be implemented?
a. Interfaces
b. Multithreading
c. Protected methods
d. Private methods
71. Static members are not inherited to subclass.
a. True
b. False
72. What would be the result if a class extends two interfaces and both have a method with
the same name and signature? Let's assume that the class is not implementing that
method.
a. Runtime error
b. Compile time error
c. Code runs successfully
d. First called method is executed successfully
73. What will be the output of the following Java program?
1.
11
class exception_handling
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
{
}
public static void main(String args[])
{
try
{
int a[] = {1, 2,3 , 4, 5};
for (int i = 0; i < 7; i++)
System.out.print(a[i]);
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.print("0");
}
}
a. 12345
b. 123450
c. 1234500
d. Compilation Error
74. Which of these keywords is not a part of exception handling?
a. try
b. finally
c. thrown
d. catch
75. 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
76. Which of these access specifiers can be used for an interface?
a. Public
b. Protected
c. private
d. All of the mentioned
77. Which of these keywords is used by a class to use an interface defined previously?
a. import
b. Import
c. implements
d. Implements
78. Interfaces specifies what class must do but not how it does
a. True
b. False
79. Which of these keywords is used to manually throw an exception?
a. try
b. finally
c. throw
d. catch
80. What happens when a constructor is defined for an interface?
a. Compilation failure
b. Runtime Exception
c. The interface compiles successfully
d. The implementing class will throw exception
81. Can “abstract” keyword be used with constructor
12
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
a. True
b. false
82. What will be the output of the following Java program?
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
class exception_handling
{
public static void main(String args[])
{
try
{
System.out.print("Hello" + " " + 1 / 0);
}
catch(ArithmeticException e)
{
System.out.print("World");
}
}
}
a. Hello
b. World
c. HelloWorld
d. Hello World
83. What will be the output of the following Java program?
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
class exception_handling
{
public static void main(String args[])
{
try
{
int a, b;
b = 0;
a = 5 / b;
System.out.print("A");
}
catch(ArithmeticException e)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
}
}
a. A
b. B
c. AC
d. BC
84. Which of the following is a super class of all exception type classes?
a. Catchable
b. RuntimeExceptions
c. String
d. Throwable
85. Which of the following operators is used to generate an instance of an exception which
can be thrown using throw?
a. thrown
13
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
b. exception
c. throws
d. new
86. Which of these classes is related to all the exceptions that can be caught by using catch?
a. Error
b. Exception
c. RuntimeExecption
d. All of the mentioned
87. A single try block must be followed by which of these?
a. Finally
b. Catch
c. Finally and catch
d. Finally or catch
e. None of the mentioned
88. Which of these exceptions handles the divide by zero error?
a. ArithmeticException
b. MathException
c. IllegalAccessException
d. IllegarException
89. Which of these statements is incorrect?
a. try block need not to be followed by catch block
b. try block can be followed by finally block instead of catch block
c. try can be followed by both catch and finally block
d. try need not to be followed by anything
90. Java supports multiple-inheritance.
a. True
b. False
91. Java Static methods cannot be accessed directly from the class level.
a. True
b. False
92. Java main method can be overridden.
a. True
b. False
93. The IS-A relationship works is bidirectional.
a. True
b. False
94. If class B extends A, and C extends B, then class C IS-A class A.
a. True
b. False
95. An abstract class can have both abstract and non-abstract methods.
a. True
b. False
96. If a class has even one abstract method, the class must be marked abstract.
a. True
b. False
97. All abstract methods must be implemented in the first concrete subclass in the inheritance
tree.
a. True
b. False
98. Instance variables live within the object they belong to, on the Heap.
a. True
14
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
b. False
99. If the instance variable is a reference to an object, both the reference and the object it
refers to are on the Heap.
a. True
b. False
100.
Is the code that runs when you say new on a class type.
a. Constructor
b. Final method
c. Garbage collector
d. Abstract method
101.
If you don’t put a constructor in your class, the compiler will put in a default
constructor.
a. True
b. False
102.
If you want a no-arg constructor, and you’ve already put in a constructor with
arguments, the compiler will put that no-arg constructor for you..
a. True
b. False
103.
An exception is always an object of type Exception
a. True
b. False
104.
The compiler does NOT pay attention to exceptions that are of type RuntimeException.
A RuntimeException does not have to be declared or wrapped in a try/catch (although
you’re free to do either or both of those things)
a. True
b. false
105.
All Exceptions the compiler cares about are called ‘unchecked exceptions’
a. True
b. false
106.
Methods that might throw a checked exception must announce it with a throws
Exception declaration.
a. True
b. false
107.
A method can only throw one kind of exception.
a. True
b. false
108.
Catch blocks can be polymorphic.
a. True
b. false
109.
Only ‘compiler checked’ exceptions can be caught.
a. True
b. false
110.
A single try block can have many different catch blocks.
a. True
b. false
111.
The sequence diagram models
a. The order in which the class diagram is constructed
b. The way in which objects communicates
c. The relationship between states
d. The components of the system
112.
Number of threads in the following code are
15
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
public class ThreadExtended extends Thread {
public void run() { System.out.println("Thread is running no");
}
public static void main(String[] args) {
ThreadExtended threadE = new ThreadExtended();
threadE.start();
}
}
a.
b.
c.
d.
113.
0
1
2
3
What is the output for the below code ?
public class Test {
public static void main(String[] args){
String value = "abc";
changeValue(value);
System.out.println(value);
}
public static void changeValue(String a){
a = "xyz";
}
}
a.
b.
c.
d.
114.
abc
xyz
Compile error
Run time error
Analyze the following code:
class Circle {
private double radius;
public Circle(double radius) {
radius = radius;
}
}
a. The program has a compile error because you cannot assign radius to radius.
16
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
b. The program will compile, but you cannot create an object of Circle with a specified
radius. The object will always have radius 0.
c. The program does not compile because Circle does not have a default constructor.
d. The program has a compilation error because it does not have a main method.
115.
Consider the following method...
public int setVar(int a, int b, float c) { ...}
Which of the following methods correctly overload the above method?
I. public int setVar(int a, float b, int c){
return (int)(a + b + c);}
II. public int setVar(int x, int y, float z){
return x+y;}
III. public float setVar(int a, int b, float c){
return c*a;}
iv. public float setVar(int a){
return a;}
a. I, III
b. I, IV
c. II, III, IV
d. I
e. III
Which of these statements is true
a. If a RuntimeException is not caught, the method will terminate and normal execution of
the thread will resume.
b. An overriding method must declare that it throws the same exception classes as the
method it overrides.
c. A method declaring that it throws a certain exception class may throw instances of any
subclass of that exception class.
d. finally blocks are executed if and only if an exception gets thrown while inside the
corresponding try block.
116.
117.
What is the output for the below code ?
public class A {
int k;
boolean istrue;
static int p;
public void printValue() {
System.out.print(k);
System.out.print(istrue);
System.out.print(p);
}
}
17
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
public class Test{
public static void main(String argv[]){
A a = new A();
a.printValue();
}
}
a.
b.
c.
d.
118.
0 false 0
0 true 0
000
Compile error, static variables must be initialized before use
Which of the following lines of code is suitable to start a thread ?
class X implements Runnable
{
public static void main(String args[])
{
/* Missing code? */
}
public void run() {}
}
119.
120.
121.
a. Thread t = new Thread(X);
b. Thread t = new Thread(X); t.start();
c. X r = new X(); Thread t = new Thread(r); t.start();
d. Thread t = new Thread(); x.run();
When you print an object, toString method is called internally
a. True
b. false
The String class overrides the equals method of the Object class
a. True
b. false
Class A {
}
Class B extends A {
}
B b1 = new B();
System.out.println ( b1 instanceof A );
a. True
b. False
c. Compile error
d. None
122.
Instance of returns true if the reference points to an object of this class or its super
class
18
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
a. True
b. false
123.
reference instanceof interface
returns true if the reference points to an object of a class implementing the interface
a. True
b. false
124.
A thread may never get a chance to run if there is always a higher-priority thread
running or a same-priority thread that never yields. This known as
a. Deadlock
b. Starvation
c. Synchronization
d. Race condition
125.
A Thread can leave the running state and go to the ready state by calling
a. yield()
b. wait()
c. sleep()
d. All of the above
126.
If you want the main thread to stop running and wait for thread t1 to complete its
execution, you just call t1.join()
a. True
b. False
127.
What a makes a thread to move to blocked state
a. Waiting for IO
b. sleep()
c. join()
d. All of them
128.
Two threads access a shared variable at the same time without synchronization where
at least one of those accesses is a write is called
a. Deadlock
b. Starvation
c. Synchronization
d. Race condition
129.
By defining a method as synchronized, this can solve the race condition problem
a. True
b. false
130.
wait(), notify(), and notifyAll() can be called in any method
a. True
b. false
131.
By using generics, you have to cast what you got out of an arrayList
a. True
b. false
132.
A generic type that can be specified as subtype of another type is called
a. Rounded generic type
b. Bounded generic type
c. Enclosed generic type
d. None of them
133.
An inner class can use all the methods and variables of the outer class, even the
private ones
a. True
b. false
134.
An inner object must be tied to a specific outer object on the heap.
19
Alexandria University
Faculty of Engineering
Computer and Communication Engineering
Specialized Scientific Programs
135.
136.
20
a. True
b. false
An inner class can be static
a. True
b. False
Sequence diagram belongs to structural diagrams
a. True
b. false
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )