Professional Documents
Culture Documents
6) class LifeTimeCycle {
void method() {
int a = 0;
int aa;
{ int b = 10; int a = 1; aa +=1; }
b+=1; }
}
a) compiler error (at aa+: variable aa not Initiated)
b) compiler error (int a in internal scope is duplicate identifier )
c) compiler error (b+=1 :variable b not found)
d) compile and run
e) a ,b, and c
7) class EqualTest {
int a, b, c;
EqualTest(int a, int b, int c) {
a = a; b = b; c = c; }
}
public class Main {
public static void main(String[] args) {
EqualTest e = new EqualTest(1,2,3);}
}
a) compiler error: in EqualTest non deterministic assignment
b) compile and run, and both all a,b ,c get the value 1
c) compile and run, but EqualTest data members not initialized
d) other
8) class EqualTest {
int a, b, c;
EqualTest(int x, int b, int c) { a = x; this.b = b; c = c; }
}
public class Main {
public static void main(String[] test) {
EqualTest test = new EqualTest(1, 2, 3);
EqualTest test_ = new EqualTest(1, 2, 4);
if (test==test_)
System.out.println("Nizar");
else if ((test.a==test_.a)&& (test.b==test_.b) && (test.c==test_.c))
System.out.println("new-tech");
else
System.out.println("Hammood");
}
}
a) output is "Nizar"
b) output is "Hammood"
c) output is both " new-tech "
e) compiler error in EqualTest non deterministic assignment
let us have those three following codes :
9) class Grand {
public void Grand() {
System.out.println("Grand Normal Constructor"); }
}
public class Main {
public static void main(String[] args) {
Grand g = new Grand();
g. Grand();}}
18) interface o {
public interface y{
protected interface pt{ } }}
a) compiler error, cannot write nested interfaces
b) compiler error, cannot be public modifier with interface y
c) compiler error, cannot be protected modifier with interface pt
d) 2,3
e) Compile and run
19) class note1{
static int out_static =0;
int out_nonstatic = 0;
static void non_nonstatic(){
out_static++;
static int i = 0;
this.out_static++;
out_static++;
}
}
a) Compiler error (static int i = 0; ) illegal start of expression
b) Compiler error (this.out_static++;) cannot use this in static method
c) Warming (this.out_static++;) : try to access static data member in
class note1
d) 1, 2
e) Others
21) class A{
class B{
static class C{ }
}
}
a) warning: C is static data member in non static class B
b) compiler error, modifier static is not allowed at class C, some solution is
making class B a static class
c) compiler error, modifier static is not allowed at class C, some solution is
making class A a static class
d) compiler error, modifier static is not allowed at class C, some solution is
making both classes B,A static classes
e) compiler error, static class C should be in package named C
25) class t{
static void tt() throws FileNotFoundException{
try{
File f = new File("C:\\myFolder");
}
catch(FileNotFoundException e){
}
}
}
Best Wishes...
Mu_Nizar & Adel Al- Jaffan
Question no Answer no Question no Answer no Question no Answer no Question no Answer no
1 d 9 a 17 D 25 C
2 a 10 d 18 C 26 C
3 a 11 a 19 D 27 e
4 b 12 B 20 E -
5 d 13 D 21 B -
6 e 14 E 22 D -
7 d 15 A 23 F -
8 c 16 E 24 d -