-
Notifications
You must be signed in to change notification settings - Fork 0
/
Master.java
172 lines (167 loc) · 4.79 KB
/
Master.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package java_quiz;
public class Master {
int n=5;
String que[] = new String[n];
char ans[] = new char[n];
Master()
{
que[0] = "What will be the output of the following?\n"
+ "class Test \r\n" +
"{ \r\n" +
" int a = 1; \r\n" +
" int b = 2; \r\n" +
"\r\n" +
" Test func(Test obj) \r\n" +
" { \r\n" +
" Test obj3 = new Test(); \r\n" +
" obj3 = obj; \r\n" +
" obj3.a = obj.a++ + ++obj.b; \r\n" +
" obj.b = obj.b; \r\n" +
" return obj3; \r\n" +
" } \r\n" +
"\r\n" +
" public static void main(String[] args) \r\n" +
" { \r\n" +
" Test obj1 = new Test(); \r\n" +
" Test obj2 = obj1.func(obj1); \r\n" +
"\r\n" +
" System.out.println(\"obj1.a = \" + obj1.a + \" obj1.b = \" + obj1.b); \r\n" +
" System.out.println(\"obj2.a = \" + obj2.a + \" obj1.b = \" + obj2.b); \r\n" +
"\r\n" +
" } \r\n" +
"} \r\n" +
"" +
"A. obj1.a = 1 obj1.b = 2\r\n" +
"obj2.a = 4 obj2.b = 3\n" +
"B. obj1.a = 4 obj1.b = 3\r\n" +
"obj2.a = 4 obj2.b = 3\n" +
"C. obj1.a = 1 obj1.b = 2\r\n" +
"obj2.a = 1 obj2.b = 2\n" +
"D. Compiler error";
ans[0] = 'B';
que[1] = "What will be the output of the following?\n"
+ "class Test \r\n" +
"{ \r\n" +
" boolean[] array = new boolean[3]; \r\n" +
" int count = 0; \r\n" +
"\r\n" +
" void set(boolean[] arr, int x) \r\n" +
" { \r\n" +
" arr[x] = true; \r\n" +
" count++; \r\n" +
" } \r\n" +
"\r\n" +
" void func() \r\n" +
" { \r\n" +
" if(array[0] && array[++count - 2] | array [count - 1]) \r\n" +
" count++; \r\n" +
"\r\n" +
" System.out.println(\"count = \" + count); \r\n" +
" } \r\n" +
"\r\n" +
"\r\n" +
" public static void main(String[] args) \r\n" +
" { \r\n" +
" Test object = new Test(); \r\n" +
" object.set(object.array, 0); \r\n" +
" object.set(object.array, 1); \r\n" +
" object.func(); \r\n" +
" } \r\n" +
"} \r\n" +
"\r\n" +
"" +
"A. 1\n" +
"B. 2\n" +
"C. 3\n" +
"D. 4";
ans[1] = 'D';
que[2] = "What will be the output of the following?\n"
+ "// filename Main.java \r\n" +
"class Grandparent { \r\n" +
" public void Print() { \r\n" +
" System.out.println(\"Grandparent's Print()\"); \r\n" +
" } \r\n" +
"} \r\n" +
"\r\n" +
"class Parent extends Grandparent { \r\n" +
" public void Print() { \r\n" +
" System.out.println(\"Parent's Print()\"); \r\n" +
" } \r\n" +
"} \r\n" +
"\r\n" +
"class Child extends Parent { \r\n" +
" public void Print() { \r\n" +
" super.super.Print(); \r\n" +
" System.out.println(\"Child's Print()\"); \r\n" +
" } \r\n" +
"} \r\n" +
"\r\n" +
"public class Main { \r\n" +
" public static void main(String[] args) { \r\n" +
" Child c = new Child(); \r\n" +
" c.Print(); \r\n" +
" } \r\n" +
"} \r\n" +
"" +
"A. Compiler Error in super.super.Print()\n" +
"B. Grandparent's Print()\r\n" +
"Parent's Print()\r\n" +
"Child's Print()\n" +
"C. Runtime Error\n" +
"D. None";
ans[2] = 'A';
que[3] = "What will be the output of the following?\n"
+ "class Base { \r\n" +
" public static void show() { \r\n" +
" System.out.println(\"Base::show() called\"); \r\n" +
" } \r\n" +
"} \r\n" +
"\r\n" +
"class Derived extends Base { \r\n" +
" public static void show() { \r\n" +
" System.out.println(\"Derived::show() called\"); \r\n" +
" } \r\n" +
"} \r\n" +
"\r\n" +
"class Main { \r\n" +
" public static void main(String[] args) { \r\n" +
" Base b = new Derived();; \r\n" +
" b.show(); \r\n" +
" } \r\n" +
"} \r\n" +
"" +
"A. Base::show() called\n" +
"B. Derived::show() called\n" +
"C. Base::show() called\n"
+ " Derived::show() called\n" +
"D. Compiler Error";
ans[3] = 'A';
que[4] = "Which of the following is true about inheritance in Java.\r\n" +
"\r\n" +
"1) In Java all classes inherit from the Object class directly or indirectly. The Object class is root of all classes.\r\n" +
"\r\n" +
"2) Multiple inheritance is not allowed in Java.\r\n" +
"\r\n" +
"3) Unlike C++, there is nothing like type of inheritance in Java where we can specify whether the inheritance is protected, public or private.\n\n" +
"A. 1,2\n" +
"B. 2,3\n" +
"C. 1,3\n" +
"D. 1,2,3";
ans[4] = 'D';
}
public void display(int i)
{
System.out.println("\n"+que[i]+"\n");
}
public boolean answer(char a,int i)
{
if(a==ans[i])
return true;
else
return false;
}
public void right(int i)
{
System.out.println("Right answer is : "+ans[i]);
}
}