Lara Core Java Part1
Lara Core Java Part1
Lara Technologies
Core Java – Part 1
# 102/12, 2nd Main, 5th Cross, Venkateswara College Road, Ramaiah
Garden, Chikka Adugodi, Thavarakere, Bangalore – 560029.
Phone No: 080 – 4131 0124
Lara Technologies RSTechnologies
System.out.println('a');
System.out.println(100);
1. Program System.out.println(100.9);
class Hello System.out.println(true);
{ }
public static void main(String args[]) }
{
Output:
System.out.println("Hello Hello to all
to all"); a
} 100
} 100.9
Output: true
Hello to all
4. Program
2. Program class A
class HelloToAll {
{ public static void main(String args[])
public static void main(String args[]) {
{ String s1="Hello to all";
System.out.println("Hello to char c1='a';
all"); int i=100;
System.out.println("Hello to double d1=100.2;
all"); boolean b1=true;
System.out.println("Hello to System.out.println(s1);
all"); System.out.println(c1);
System.out.println("Hello to System.out.println(i);
all"); System.out.println(d1);
System.out.println("Hello to System.out.println(b1);
all"); }
} }
}
Output:
Output: Hello to all
Hello to all a
Hello to all 100
Hello to all 100.2
Hello to all true
Hello to all
5. Program
3. Program class Methods
class Literals {
{ public static void main(String args[])
public static void main(String args[]) {
{ System.out.println("I am
System.out.println("Hello to in the main method");
all");
2
Lara Technologies RSTechnologies
} }
public static void test() }
{ Output:
System.out.println("I am 10
in the Test method"); 20
} 30
} 8. Program
Output:I am in the main method class C
{
6. Program public static void main(String args[])
class Methods1 {
{ System.out.println("Main method
public static void test() Begins");
{ test1();
System.out.println("I am in the Test test1();
method"); test1();
} System.out.println("Main method
public static void main(String args[]) ends");
{ }
System.out.println("I am in the main public static void test1()
method"); {
} System.out.println("Test Method");
public static void test1() }
{ }
System.out.println("I am in Output:
the Test1 method"); Main method Begins
} Test Method
} Test Method
Output: Test Method
I am in the main method Main method ends
9. Program
7. Program class D
class B {
{ public static void main(String args[])
public static void main(String args[]) {
{ System.out.println("Main Method");
int i=10; test1();
System.out.println(i); test2();
i=20; System.out.println("End method");
System.out.println(i); }
i=30; public static void test1()
System.out.println(i); {
3
Lara Technologies RSTechnologies
System.out.println("Test1 method"); test1();
} System.out.println("Test ends");
public static void test2() }
{ public static void test1()
System.out.println("Test2 method"); {
} System.out.println("Test1 Method");
} test2();
Output: System.out.println("Test1 Ends");
Main Method }
Test1 method public static void test2()
Test2 method {
End method System.out.println("Test2 Method");
int i=10;
System.out.println(i);
10. Program System.out.println("Test2 Ends");
class E }
{ }
public static void main(String args[]) Output:
{ Main Method
System.out.println("Main Method"); Test Method
int i=10; Test1 Method
System.out.println(i); Test2 Method
} 10
public static void test() Test2 Ends
{ Test1 Ends
System.out.println(i); Test ends
} Main Ends
} 12. Program
Output: class H
Compile Time Error {
11. Program public static void main(String args[])
class G {
{ test(1);
public static void main(String args[]) int i=10;
{ test(i);
System.out.println("Main Method"); test();
test(); }
System.out.println("Main Ends"); public static void test(int i)
} {
public static void test() System.out.println(i);
{ }
System.out.println("Test Method"); }
4
Lara Technologies RSTechnologies
Output: {
Compile Time Error int i=10;
13. Program i=test1(i);
class I System.out.println(i);
{ }
public static void main(String args[]) public static int test1(int i)
{ {
int i=10; i=200;
test1(i); return i;
System.out.println(i); }
} }
public static void test1(int i) Output:
{ 200
i=100;
} 16. Program
} class M
Output: {
10 public static void main(String args[])
{
int i=10;
14. Program System.out.println(i);
class J i=test(i);
{ System.out.println(i);
public static void main(String args[]) }
{ public static int test(int k)
int i=10; {
System.out.println(i); k=300;
test1(i); return k;
System.out.println(i); }
} }
public static void test1(int m)
Output:
{ 10
m=100; 300
}
17. Program
} class N
Output: {
10 public static void main(String args[])
10 {
15. Program test1();
System.out.println(2);
class K }
{ public static void test1()
public static void main(String args[])
5
Lara Technologies RSTechnologies
{ System.out.println(j);
System.out.println(1); }
return; }
} Output:
} Compile Time Error
Output: 21. Program
1 class C
2 {
public static void main(String args[])
18. Program {
class A int i=10,j=10;
{ System.out.println(i);
public static void main(String args[]) System.out.println(j);
{ }
int i; }
System.out.println(i); Output:
} 10
} 10
Output: 22. Program
Compile Time Error class D
{
19. Program public static void main(String args[])
class A1 {
{ int i;
public static void main(String args[]) test(i);
{ System.out.println(i);
int i=10; }
System.out.println(i); public static void test(int k)
} {
} System.out.println(k);
Output: 10 }
}
Output:
Compile Time Error
20. Program 23. Program
class B class D1
{ {
public static void main(String args[]) public static void main(String args[])
{ {
int i,j; int i=10;
i=j; test(i);
System.out.println(i); System.out.println(i);
6
Lara Technologies RSTechnologies
} }
public static void test(int k) Output:
{ 10
System.out.println(k); 10
} 27. Program
} class H
Output: {
10 public static void main(String args[])
10 {
24. Program int i;
class E test(i=10);
{ System.out.println(i);
public static void test(int i) }
{ public static void test(int k)
System.out.println(i); {
int k; System.out.println(k);
k=0; }
System.out.println(k); }
} Output:
} 10
Output: 10
Run Time Error 28. Program
25. Programs class I
class F {
{ public static void main(String args[])
public static void main(String args[]) {
{ System.out.println(i);
int i; int i;
System.out.println(i=10); }
} }
} Output:
Output: Compile Time Error
10 29. Program
26. Program class I1
class G {
{ public static void main(String args[])
public static void main(String args[]) {
{ int i=10;
int i; System.out.println(i);
System.out.println(i=10); }
System.out.println(i); }
} Output:
7
Lara Technologies RSTechnologies
10 class K
30. Program {
class J public static void main(String args[])
{ {
public static void main(String args[]) int i;
{ System.out.println("Hello");
int i=0; }
System.out.println(i); }
int i=1; Output:
System.out.println(i); Hello
} 34. Program
} class M
Output: {
Compile Time Error public static void main(String args[])
31. Program {
class J1 int i=10;
{ test(i);
public static void main(String args[]) }
{ public static void test(int k)
int i=0; {
System.out.println(i); int k=20;
double i=1; System.out.println(k);
System.out.println(i); }
} }
} Output:
Output: Compile Time Error
Compile Time Error 35. Program
32. Program class M1
class J2 {
{ public static void main(String args[])
public static void main(String args[]) {
{ int i=10;
int i=0; test(i);
System.out.println(i); System.out.println(i);
int j=1; }
System.out.println(j); public static void test(int k)
} {
} int n=20;
Output: System.out.println(k);
0 }
1 }
33. Program Output:
8
Lara Technologies RSTechnologies
10 public static void test(int i,double i)
10 {
36. Program System.out.println(i);
class M2 System.out.println(j);
{ }
public static void main(String args[]) }
{ Output:
int i=10; Compile Time Error
test(i); 39. Program
System.out.println(i); class N2
} {
public static void test(int k) public static void main(String args[])
{ {
int n=20; test(2,3);
System.out.println(n); }
} public static void test(int i,int j)
} {
Output: System.out.println(i);
20 System.out.println(j);
10 }
37. Program }
class N Output: 2
{ 3
public static void main(String args[]) 40. Program
{ class O
test(2,3); {
} public static void main(String args[])
public static void test(int i,int i) {
{ test(10);
System.out.println(i); }
System.out.println(j); public static void test(int k=20)
} {
} System.out.println(k);
Output: }
Compile Time Error }
38. Program Output:
class N1 Compile Time Error
{
public static void main(String args[]) 41. Program
{ class P
test(2,3); {
} public static void test(int i)
9
Lara Technologies RSTechnologies
{ Output:
i=10; Compile time error
System.out.println(i); 44. Program
} class A
public static void main(String args[]) {
{ public static void main(String[] args)
test(11); {
} int i=09;
} i=test(i);
Output: System.out.println(i);
10 }
42. Program test(int i)
class HelloAll {
{ return i;
public static void main(String[] args) }
{ }
System.out.println("helloworld"); Output:
test(10); Compile time error
System.out.println("test ended"); 45. Program
} class HelloAll
Static void test(int i) {
{ public static void main(String[] args)
System.out.println("i"); {
} System.out.println("helloworld");
} test();
Output: System.out.println("test ended");
helloworld }
i static void test(int i)
test ended {
43. Program System.out.println(i);
class HelloAll }
{ }
public static void main(String[] args) Output:
{ Compile time error
System.out.println("helloworld");
test(10); 46. Program
System.out.println("test ended"); class HelloAll
} {
void test(int i) public static void main(String[] args)
{ {
System.out.println("i"); int i;
} i++;
}
10
Lara Technologies RSTechnologies
System.out.println(i); Output:
} Compile time error
} 49. Program
Output: class Manager1
Compile time error {
47. Program public static void main(String[] args)
class HelloAll {
{ test();
public static void main(String[] args) }
{ static int test()
int i=11; {
i++; int j=15;
System.out.println(i); System.out.println(j);
} return j;
} }
Output: }
12 Output:
48. Program 15
class Manager 50. Program
{ class Manager1
public static void main(String[] args) {
{ public static void main(String[] args)
System.out.println(i); {
int i=10; int i;
System.out.println(i); test((i=10)*25);
} }
} static void test(int i)
Output: {
Compile time error System.out.println(i);
Program }
class Manager1 }
{ Output:
public static void main(String[] args) 250
{ 51. Program
test(); class Manager
} {
void test() public static void main(String args[])
{ {
int j; Manager mgr=null;
System.out.println(j); System.out.println(mgr);
} }
} }
11
Lara Technologies RSTechnologies
Output: compile time error
Null
52. Program 55. Program
class Manager class Manager
{ {
public static void main(String args[]) public static void main(String args[])
{ {
Manager mgr=null,mgr1=null,mgr2; boolean flag=true;
System.out.println(mgr2); if(flag)
} {
} System.out.println("true");
Output: }
compile time error else
53. Program {
class Manager System.out.println("false");
{
public static void main(String args[]) }
{ }
Manager mgr=null,mgr1=null,mgr2; }
mgr2=mgr1=mgr; Output:
System.out.println(mgr2); true
} 56. Program
} class Manager
Output: {
null public static void main(String args[])
54. Program {
class Manager int i=1;
{ int j=2;
public static void main(String args[]) int l=3;
{ int m;
boolean flag; System.out.println(i);
if(flag) System.out.println(j);
{ System.out.println(l);
System.out.println("true"); System.out.println(m);
} }
else }
{ Output:
System.out.println("false"); compile time error
} 57. Program
} class Manager
} {
Output: public static void main(String args[])
12
Lara Technologies RSTechnologies
{ {
int i=1; System.out.println("false");
int j=2;
int l=3; }
System.out.println(i); }
System.out.println(j); }
System.out.println(l); Output:
} compile time error
} 60. Program
Output: class Manager
1 {
2 public static void main(String args[])
3 {
58. Program boolean flag=false;
class Manager if(flag=false)
{ {
public static void main(String args[]) System.out.println("true");
{ }
boolean flag; else
if(flag=true) {
{ System.out.println("false");
System.out.println("true"); }
} }
else }
{ Output:
System.out.println("false"); false
61. Program
} class Manager1
} {
} public static void main(String args[])
Output: true {
59. Program int i=1;
class Manager i=i+10;
{ System.out.println(i);
public static void main(String args[]) }
{ }
boolean flag; Output:
if(flag="true") 11
{ 62. Program
System.out.println("true");
} class A
else {
13
Lara Technologies RSTechnologies
public static void main(String args[]) {
{ int i=10;
int i=0; test(i++);
System.out.println(i++); test(i);
System.out.println(i); }
} public static void test(int k)
} {
Output: System.out.println(k);
0 }
1 }
63. Program Output:
class B 10
{ 11
public static void main(String args[]) 66. Program
{ class E
int i=0; {
System.out.println(i--); public static void main(String args[])
System.out.println(i); {
} int i=10;
} int j=i++;
Output: System.out.println(i);
0 System.out.println(j);
-1 }
64. Program }
class C Output:
{ 11
public static void main(String args[]) 10
{ 67. Program
int i=10; class F
test(i--); {
} public static void main(String args[])
public static void test(int i) {
{ int i=10;
System.out.println(i); int j=i++;
} int k=i--;
} System.out.println(i);
Output: System.out.println(j);
10 System.out.println(k);
65. Program }
class D }
{ Output:
public static void main(String args[]) 10
14
Lara Technologies RSTechnologies
10 {
11 public static void main(String args[])
68. Program {
class H int i=0;
{ test(--i);
public static void main(String args[]) }
{ public static void test(int k)
int i=0; {
i=i++; System.out.println(k);
System.out.println(i); }
} }
} Output:
Output: -1
0 72. Program
69. Program class L
class I {
{ public static void main(String args[])
public static void main(String args[]) {
{ int i=10;
int k=10; i=++i;
k=k--; System.out.println(i);
System.out.println(k); }
} }
} Output:
Output: 11
10 73. Program
70. Program class M
class J {
{ public static void main(String args[])
public static void main(String args[]) {
{ int i=0;
int i=0; i=i++ + i++ + i++;
int j=++i; System.out.println(i);
System.out.println(i); }
System.out.println(j); }
} Output:
} 3
Output: 74. Program
1 class N
1 {
71. Program public static void main(String args[])
class K {
15
Lara Technologies RSTechnologies
int i=10; public static void main(String args[])
i=i++ + i-- + ++i; {
System.out.println(i); int i=0;
} i=++i + i-- + test(++i) + ++i;
} System.out.println(i);
Output: }
32 public static int test(int i)
75. Program {
class O return ++i;
{ }
public static void main(String args[]) }
{ Output:
int i=0; 6
i=i+++test(i); 78. Program
System.out.println(i); class R
} {
public static int test(int i) public static void main(String args[])
{ {
return i++; int i=0;
} i=i++ + test1(i++) + test1(++i) +
} test2(i++) + test2(++i);
Output: System.out.println(i);
1 }
76. Program public static int test1(int i)
class P {
{ return i++;
public static void main(String args[]) }
{ public static int test2(int i)
int i=0; {
i=i+++test(i++)+i; return ++i;
System.out.println(i); }
} }
public static int test(int i) Output:
{ 14
return i++; 79. Program
} class Manager1
} {
Output: public static void main(String args[])
3 {
77. Program int i=test();
class Q System.out.println(i);
{ }
16
Lara Technologies RSTechnologies
static int test(int i) int i=0;
{ i=i++ +i*10;
return(i*i); System.out.println(i);
} }
} }
Output: Output:
compile time error 10
80. Program 83. Program
class Manager1 class Manager1
{ {
public static void main(String args[]) public static void main(String args[])
{ {
int i=test(10); int i=10;
System.out.println(i); i=i++ +i-- +i*10;
} System.out.println(i);
static int test(int i) }
{ }
return i*i; Output:
} 121
} 84. Program
Output: class Manager1
100 {
81. Program public static void main(String args[])
class Manager1 {
{ int i=0;
public static void main(String args[]) i=i++ +get(i)+ ++i +i*10;
{ System.out.println(i);
int i=test(); }
System.out.println(i); static int get(int i)
} {
static int test() return i*1;
{ }
return 9; }
} Output:
} 23
Output: 85. Program
9 class Manager1
82. Program {
class Manager1 public static void main(String args[])
{ {
public static void main(String args[]) int i=3;
{ i++;
17
Lara Technologies RSTechnologies
System.out.println(i); int i=30;
} System.out.println(i);
} }
Output: }
4 Output:
86. Program 20
class A 10
{ 20
public static void main(String args[]) 30
{ 20
System.out.println(1); 88. Program
test(); class C
System.out.println(2); {
} public static int i;
public static void test() public static void main(String args[])
{ {
System.out.println(3); System.out.println(i);
} test();
} System.out.println(i);
Output: }
1 public static void test()
3 {
2 i=20;
87. Program }
class B }
{ Output:
public static void test1() 0
{ 20
int i=10; 89. Program
System.out.println(i); class D
} {
public static void main(String args[]) static int i=10;
{ static void test()
int i=20; {
System.out.println(i); System.out.println(i);
test1(); }
System.out.println(i); public static void main(String args[])
test2(); {
System.out.println(i); System.out.println(i);
} i=20;
public static void test2() test();
{ i=30;
18
Lara Technologies RSTechnologies
test(); System.out.println(j);
} }
} }
Output: Output:
10 10
20 10
30 92. Program
90. Program class G
class E {
{ static int i=j;
static int i=0; static int j=10;
static int j=10; public static void main(String args[])
static void print() {
{ System.out.println(i);
System.out.println(i); System.out.println(j);
System.out.println(j); }
} }
public static void main(String args[]) Output:
{ Compile Time Error
print(); 93. Program
i=j=20; class H
print(); {
i=30; static int i=test();
j=40; static int j=10;
print(); static int test()
} {
} return j;
Output: }
0 public static void main(String args[])
10 {
20 System.out.println(i);
20 System.out.println(j);
30 }
40 }
91. Program Output:
class F 0
{ 10
static int i=10; 94. Program
static int j=i; class I
public static void main(String args[]) {
{ static int i;
System.out.println(i); static int j=10;
19
Lara Technologies RSTechnologies
static }
{ Output:
i=100; SIB method
j=200; Main method
} 97. Program
public static void main(String args[]) public class A
{ {
System.out.println(i); static int i;
System.out.println(j); static int j=10;
} static
} {
Output: System.out.println(i);
100 System.out.println(j);
200 i=100;
95. Program j=200;
class J }
{ static
static {
{ System.out.println(i);
System.out.println("I am in the SIB System.out.println(j);
of J"); i=1000;
} j=2000;
public static void main(String args[]) }
{ public static void main(String[] args)
System.out.println("I am in the main {
method"); System.out.println(i);
} System.out.println(j);
}
Output: }
I am in the SIB of J }
I am in the main method Output:
96. Program 0
class K 10
{ 100
public static void main(String args[]) 200
{ 1000
System.out.println("Main method"); 2000
} 98. Program
static public class B
{ {
System.out.println("SIB method"); static int i;
} static
20
Lara Technologies RSTechnologies
{ int i=200;
System.out.println(i); System.out.println(i);
i=100;
} }
public static void main(String[] args)
{ }
System.out.println(i); Output:
} 1000
static 200
{ 101. Program
System.out.println(i); public class F
i=200; {
} static int i=10;
public static void main(String[] args)
} {
Output: System.out.println(i);
0 int i=20;
100 System.out.println(i);
200 System.out.println(F.i);
99. Program }
class c
{ }
static int i=10; Output:
} 10
public class D 20
{ 10
static int i=100; 102. Program
public static void main(String[] args) class H
{ {
int i=1000; static int i;
System.out.println(i); }
} class G
} {
Output: public static void main(String[] args)
1000 {
100. Program System.out.println(H.i);
public class E }
{
static int i=1000; }
public static void main(String[] args) Output:
{ 0
System.out.println(i); 103. Program
21
Lara Technologies RSTechnologies
class I }
{ }
static int j=10; public class T
} {
static void test()
class K {
{ System.out.println("i am in the test
static int j=20; of T");
} }
public class M public static void main(String[] args)
{ {
static int j=30; test();
public static void main(String[] args) T.test();
{ S.test();
int j=40; R.test();
System.out.println(M.j); }
System.out.println(K.j); }
System.out.println(M.j); Output:
System.out.println(j); i am in the test of T
} i am in the test of T
i am in the test of S
} i am in the test of R
Output: 105. Program
30 class X
20 {
30 static int i=100;
40 static void test()
104. Program {
105.class R System.out.println("i am in the test
{ of X");
static void test() }
{ }
System.out.println("i am in the test public class Manager
of R"); {
} public static void main(String[] args)
} {
class S X.test();
{ }
static void test() }
{ Output:
System.out.println("i am in the test i am in the test of X
of S"); 106. Program
22
Lara Technologies RSTechnologies
class Y static int i=10;
{ static
static int i=100; {
} System.out.println("i am in the sib of
public class Z A");
{ }
public static void main(String[] args) }
{ class B
System.out.println(Y.i); {
} static void test()
} {
Output: System.out.println("i am in the test
100 of B");
107. Program }
class TEST1 static
{ {
static System.out.println("i am in the sib of
{ B");
System.out.println("i am in the }
SIB"); }
} class Manager1
} {
public class TEST2 public static void main(String args[])
{ {
static System.out.println("i am in the
{ main");
System.out.println("i am in the System.out.println(A.i);
TEST2"); B.test();
} }
public static void main(String[] args) }
{ Output:
System.out.println("i am in the main i am in the main
TEST2"); i am in the sib of A
} 10
i am in the sib of B
} i am in the test of B
Output: 109. Program
i am in the TEST2 class A
i am in the main TEST2 {
108. Program static
class A {
{
23
Lara Technologies RSTechnologies
System.out.println("i am in the sib of i am in the sib of B
A"); 20
} i am in the sib of A
static void test1() i am in the test1 of A
{ i am in the test2 of A
System.out.println("i am in the test1 110. Program
of A"); class A
} {
static void test2() static
{ {
System.out.println("i am in the test2 System.out.println("i am in the sib of
of A"); A");
} }
static void test1()
} {
class B System.out.println("i am in the test1
{ of A");
static int i=20; }
static void test() static void test2()
{ {
System.out.println("i am in the test System.out.println("i am in the test2
of B"); of A");
} }
static }
{ class B
System.out.println("i am in the sib of {
B"); static int i=20;
} static void test()
} {
class Manager1 System.out.println("i am in the test
{ of B");
public static void main(String args[]) }
{ static
System.out.println("i am in the {
main"); System.out.println("i am in the sib of B");
A.test1(); }
A.test2(); }
B.test(); class Manager2
} {
} public static void main(String args[])
Output: {
i am in the main
24
Lara Technologies RSTechnologies
System.out.println("i am in the }
main"); static
System.out.println(B.i); {
B.test(); System.out.println("i am in the sib of
B.test(); B");
} }
} }
Output: class Manager1
i am in the main {
i am in the sib of A public static void main(String args[])
i am in the test1 of A {
i am in the test2 of A System.out.println("i am in the
i am in the sib of B main");
i am in the test of B System.out.println(B.i);
A.test1();
111. Program A.test2();
class A B.test();
{ }
static }
{ Output:
System.out.println("i am in the sib of i am in the main
A"); i am in the sib of B
} 20
static void test1() i am in the sib of A
{ i am in the test1 of A
System.out.println("i am in the test1 i am in the test2 of A
of A"); i am in the test of B
} 112. Program
static void test2() class ManagerA
{ {
System.out.println("i am in the test2 static
of A"); {
} System.out.println("i am in the sib of
A");
} }
class B public static void main(String[] args)
{ {
static int i=20; System.out.println("i am in the
static void test() main");
{ }
System.out.println("i am in the test }
of B"); class Manager1
25
Lara Technologies RSTechnologies
{ static
static {
{ System.out.println("i am in the sib of
System.out.println("i am in the sib of B");
B"); }
} public static void main(String[] args)
public static void main(String[] args) {
{ Test.method1();
System.out.println("manager1 main System.out.println("test main
begin"); begin");
ManagerA.main(args); System.out.println("test main end");
System.out.println("manager1 main }
end"); }
} Output:
} i am in the sib of B
Output: i am in the sib of test
i am in the sib of B i am in the method1 in the test
manager1 main begin test main begin
i am in the sib of A test main end
i am in the main 114. Program
manager1 main end class Test
113. Program {
class Test static void method1()
{ {
static void method1() System.out.println("i am in
{ the method1 in the test");
System.out.println("i am in the }
method1 in the test"); static
} {
static System.out.println("i am in the sib of
{ test");
System.out.println("i am in the sib of }
test"); public static void main(String[] args)
} {
public static void main(String[] args) System.out.println("i am in the
{ main");
System.out.println("i am in the }
main"); }
} class test2
} {
class Manager1 static
{ {
26
Lara Technologies RSTechnologies
System.out.println("i am in the sib of }
B"); Output:
} i am in the main
public static void main(String[] args) i am in the main
{ 116. Program
Test.method1(); class Manager1
System.out.println("test main {
begin"); static
System.out.println("test main end"); {
} String all[]=new String[0];
} main(all);
class Manager1 }
{ public static void main(String args[])
public static void main(String args[]) {
{ System.out.println("i am in the
System.out.println("i am in the main main");
begin"); }
test2.main(args); }
System.out.println("i am in the min Output:
end"); i am in the main
}
} 117. Program
Output: class Manager1
Iam in the main begin {
i am in the sib of B static
i am in the sib of test {
i am in the method1 in the test String all[]=new String[0];
test main begin main(all);
test main end main(null);
i am in the min end }
115. Program public static void main(String args[])
class Manager1 {
{ System.out.println("i am in the
static main");
{ }
main(null); }
} Output:
public static void main(String args[]) i am in the main
{
System.out.println("i am in the 118. Program
main"); class Person
} {
27
Lara Technologies RSTechnologies
String name; {
int age; public static void main(String args[])
double weight; {
double height; Person p=new Person();
double FindRunrate() p.name="Ramesh";
{ p.age=29;
double rate=(age/weight)*height; p.weight=59.00;
return rate; p.height=5.9;
System.out.println(p.name);
} System.out.println(p.age);
} System.out.println(p.weight);
class Manager1 System.out.println(p.height);
{ double rate=p.FindRunrate();
public static void main(String args[]) System.out.println(rate);
{ }
Person p=new Person(); }
System.out.println(p.name); Output:
System.out.println(p.age); Ramesh
System.out.println(p.weight); 29
System.out.println(p.height); 59.0
} 5.9
} 2.9000000000000004
Output: 120. Program
null class Person
0 {
0.0 String name;
0.0 int age;
119. Program double weight;
class Person double height;
{ double FindRunrate()
String name; {
int age; double rate=(age/weight)*height;
double weight; return rate;
double height;
double FindRunrate() }
{ }
double rate=(age/weight)*height; class Manager1
return rate; {
public static void main(String args[])
} {
} Person p=new Person();
class Manager1 Person p1=new Person();
28
Lara Technologies RSTechnologies
Person p2=new Person(); int pages()
p.name="Ramesh"; {
p.age=29; return pages;
p.weight=59.00; }
p.height=5.9;
p1.name="Praveen"; }
p1.age=25; class Manager1
p1.weight=63.00; {
p1.height=5.8; public static void main(String args[])
p2.name="kiran"; {
p2.age=24; Book b=new Book();
p2.weight=55.00; b.author="Ramesh";
p2.height=5.10; b.pages=500;
double rate=p.FindRunrate(); b.title="corejava";
System.out.println(p.name); b.weight=2;
System.out.println(rate); System.out.println(b.author());
rate=p1.FindRunrate(); System.out.println(b.title);
System.out.println(p1.name); System.out.println(b.pages);
System .out.println(rate); System.out.println(b.weight);
rate=p2.FindRunrate(); }
System.out.println(p2.name); }
System.out.println(rate); Output:
} Ramesh
} corejava
Output: 500
Ramesh 2.0
2.9000000000000004 122. Program
Praveen class Book
2.3015873015873014 {
kiran String title;
2.225454545454545 String author;
121. Program double weight;
class Book int pages;
{ double weight()
String title; {
String author; return weight;
double weight; }
int pages; String title()
String author() {
{ return title;
return author; }
}
29
Lara Technologies RSTechnologies
} {
Person1 p1=new Person1();
class Manager1
Person1 p2;
{
p1.name="Ramesh";
public static void main(String args[])
p1.age=29;
{
p1.weight=59.00;
Book b=new Book();
p1.height=5.9;
b.author="Ramesh"; p2=p1;
b.pages=500;
b.title="corejava"; p1.showdays();
b.weight=2; p2.showdays();
System.out.println(b.author); p1=null;
System.out.println(b.title); p1.showdays();
System.out.println(b.pages);
System.out.println(b.weight); }
System.out.println(b.title()); }
System.out.println(b.weight()); Output:
youare10585daysold
} youare10585daysold
} Null pointer exception
Output: 124. Program
Ramesh class A
corejava {
500 int i;
2.0 }
corejava class Manager
{
2.0
public static void main(String args[])
123. Program {
class Person1 A a1=new A();
{ A a2=new A();
String name; A a3=new A();
int age; A a4=new A();
double weight; a1.i=20;
System.out.println("a1.i="+a1.i);
double height;
}
void showdays() }
{ Output:
System.out.println("youare"+age*36 a1.i=20
5+"daysold"); 125. Program
} class A
} {
class Manager1 int i;
{ }
class Manager
public static void main(String args[])
30
Lara Technologies RSTechnologies
{ {
public static void main(String args[]) B b1=new B();
{ B b2=new B();
A a1=new A(); B b3=new B();
A a2=new A(); B b4=new B();
A a3=new A(); b1.i=22;
A a4=new A(); b2.i=33;
a1.i=20; System.out.println("b1.i="+b1.i);
a2.i=30; System.out.println("b2.i="+b2.i);
System.out.println("a1.i="+a1.i); System.out.println("b3.i="+b3.i);
System.out.println("a2.i="+a2.i); System.out.println("b4.i="+b4.i);
System.out.println("a3.i="+a3.i); }
System.out.println("a4.i="+a4.i); }
}
} Output:
Output: b1.i=33
a1.i=20 b2.i=33
a2.i=30 b3.i=33
a3.i=0 b4.i=33
a4.i=0 128. Program
126. Program class Manager
class C {
{ static int i=10;
int i; static
} {
class Manager Manager m1=new Manager();
{ m1.i=10;
public static void main(String args[]) System.out.println(m1.i);
{ }
C c1=new C(); public static void main(String args[])
C c2=new C(); {
C c3=new C(); Manager m1=new Manager();
C c4=new C(); System.out.println("m1.i="+m1.i);
c1.i=20; }
c2.i=30; }
System.out.println("c3.i="+c3.i); Output:
} 10
} m1.i=10
Output: 129. Program
c3.i=0 class Manager
127. Program {
class B int i=20;
{ static
static int i; {
} Manager m1=new Manager();
class Manager m1.i=10;
{ System.out.println(m1.i);
public static void main(String args[]) }
31
Lara Technologies RSTechnologies
public static void main(String args[]) A a4=new A();
{ a1.i=19;
Manager m1=new Manager(); System.out.println("a1.i="+a1.i);
System.out.println("m1.i="+m1.i); }
} }
} Output:
Output: a1.i=19
10 132. Program
m1.i=20 class A
130. Program {
class A int i;
{ A()
int i; {
} i++;
class Manager }
{ A(int k)
public static void main(String args[]) {
{ i++;
A a1=new A(); }
A a2=new A(); }
A a3=new A(); class Manager
A a4=new A(); {
a1.i=19; public static void main(String args[])
System.out.println("a1.i="+a1.i); {
} A a1=new A();
} A a2=new A();
Output: A a3=new A();
a1.i=19 A a4=new A();
131. Program System.out.println("a1.i="+a1.i);
class A }
{ }
int i; Output:
A() a1.i=1
{ 133. Program
i++; class A
} {
A(int k) static int i;
{ }
i++; class Manager
} {
} public static void main(String args[])
class Manager {
{ A.i=19;
public static void main(String args[]) System.out.println(A.i);
{ A a1=new A();
A a1=new A(); System.out.println(a1.i);
A a2=new A(); A a2=new A();
A a3=new A(); System.out.println(a2.i);
32
Lara Technologies RSTechnologies
System.out.println("a2.i="+a2.i); System.out.println(a1.i);
} a1.i=10;
} A a2=a1;
Output: System.out.println(a2.i);
19 a2.i=20;
19 System.out.println(a1.i);
19 }
a2.i=19 }
134. Program Output:
class A 0
{ 10
static void test() 0
{ 10
System.out.println("I am in the 20
test"); 136. Program
} class B
} {
class Manager int q;
{ static int p;
public static void main(String args[]) }
{ class Manager1
A a1=new A(); {
A a2=new A(); public static void main(String args[])
A a3=new A(); {
A a4=new A(); B b1 = new B();
a1.test(); B b2 = new B();
a2.test(); B b3 = null;
a3.test(); System.out.println(b1.q);
} System.out.println(b2.q=20);
} b3=b2;
Output: System.out.println(b3.q);
I am in the test b3.q=30;
I am in the test System.out.println(b2.q);
I am in the test System.out.println(b1.q=100);
135. Program System.out.println(b1.q);
class A System.out.println(B.p);
{ }
int i; }
static int j; Output:
} 0
class Manager 20
{ 20
public static void main(String args[]) 30
{ 100
System.out.println(A.j); 100
A.j=10; 0
System.out.println(A.j); 137. Program
A a1 = new A(); class C
33
Lara Technologies RSTechnologies
{ Run Time Error:java.lang.NullPointerException
int i; 139. Program
static int j; class E
} {
class Manager2 int i;
{ }
public static void main(String args[]) class Manager4
{ {
C c1 = null; public static void main(String args[])
C c2 = null; {
C c3 = c1; E e1= null;
c2 = new C(); e1.i=10;
c3=c1=c2; System.out.println("Main Ends");
c1.i=100; }
System.out.println(c2.i); }
System.out.println(c3.i); Output:
C.j=200; Compile Time Success
System.out.println(C.j); java.lang.NullPointerException
System.out.println(c1.i); 140. Program
}
class F
}
{
Output: static int i;
100 }
100 class Manager4
200 {
100 public static void main(String args[])
138. Program {
class D F f1 =new F();
{ f1.i=100;
int i; System.out.println(f1.i);
int j; F f2 =new F();
static int k; System.out.println(f2.i);
} f2.i=200;
class Manager3 System.out.println(f1.i);
{ }
public static void main(String args[]) }
{ Output:
D d1 =new D(); 100
System.out.println(d1.i); 100
d1=null; 200
System.out.println(d1.j); 141. Program
System.out.println(D.k);
class G
}
{
}
int i;
}
Output: class Manager5
Compile Success
{
0
public static void main(String args[])
34
Lara Technologies RSTechnologies
{ System.out.println(b1.i);
System.out.println(G.i); System.out.println(b2.i);
} }
} }
Output: Output:
Compile Time Error Cons1
non-static variable i cannot be referenced from a 0
static Cons2
142. Program 0
class A 10
{ 10
int i; 144. Program
} class C
class Manager {
{ int i;
public static void main(String args[]) C()
{ {
A a1 = new A(); System.out.println("Hello to all");
System.out.println(a1.i); }
a1.i=10; }
System.out.println(a1.i); class Manager1
} {
} public static void main(String args[])
Output: {
0 C c1 =new C();
10 System.out.println(c1.i);
143. Program c1.i=10;
class B System.out.println(c1.i);
{ }
int i; }
B() Output:
{ Hello to all
System.out.println("Cons1"); 0
} 10
B(int i) 145. Program
{ class D
System.out.println("Cons2"); {
} int i;
} D(int i)
class Manager1 {
{ System.out.println("cons1");
public static void main(String args[]) }
{ D()
B b1 = new B(); {
System.out.println(b1.i); System.out.println("cons2");
B b2= new B(10); }
System.out.println(b2.i); }
b1.i=b2.i=10; class Manager2
35
Lara Technologies RSTechnologies
{ System.out.println("-----------");
public static void main(String args[]) E e3 = new E(100);
{ }
D d1 = new D(); }
System.out.println("----------"); Output:
D d2 = new D(); cons3
System.out.println("----------"); -----------
D d3 = new D(10); cons1
System.out.println("----------"); -----------
D d4 = new D(20); cons2
System.out.println("----------"); 147. Program
new D(); class F
} {
} int i;
Output: F()
cons2 {
---------- i=10;
cons2 }
---------- F(int k)
cons1 {
---------- i=k;
cons1 }
---------- }
cons2 class Manager5
146. Program {
class E public static void main(String args[])
{ {
int i; F f1 =new F();
E(double i) System.out.println(f1.i);
{ F f2 =new F(20);
System.out.println("cons1"); System.out.println(f2.i);
} }
E(int i) }
{ Output:
System.out.println("cons2"); 10
} 20
E() 148. Program
{ class A
System.out.println("cons3"); {
} int i;
} static int j;
class Manager3 void test()
{ {
public static void main(String args[]) System.out.println(i);
{ }
E e1 = new E(); static void test1()
System.out.println("-----------"); {
E e2 = new E(10.20); System.out.println(j);
36
Lara Technologies RSTechnologies
} class A
} {
class Manager int i;
{ static int j;
public static void main(String args[]) A()
{ {
A a1 = new A(); System.out.println(i);
System.out.println(a1.i); System.out.println(j);
a1.test(); }
A.test1(); void print()
} {
} System.out.println(i);
Output: System.out.println(j);
0 }
0 }
0 class Manager
149. Program {
class B public static void main(String args[])
{
{
A a1 = new A();
int i;
a1.print();
static int j;
A a2 = new A();
int get()
a2.i=10;
{
a2.j=20;
return i;
a2.print();
}
}
void set(int i)
}
{
this.i=i; Output:
0
}
0
}
0
class Manager1
0
{
0
public static void main(String args[])
0
{
10
B b1 = new B();
20
System.out.println(b1.i);
b1.i=10; 151. Program
int k = b1.get(); class B
System.out.println(k); {
b1.set(20); int i;
System.out.println(b1.get()); static int j;
} B(int i,int j)
} {
Output: i=i;
0 j=j;
10 }
20 void print()
150. Program {
System.out.println(i);
37
Lara Technologies RSTechnologies
System.out.println(j); static int j;
} public static void main(String args[])
public static void main(String args[]) {
{ D d1 = new D();
B b1 = new B(10,20); d1.i=10;
b1.print(); j=20;
} System.out.println(d1.i);
} System.out.println(d1.j);
Output: D d2 = new D();
0 d2.i=100;
0 j=200;
152. Program System.out.println(d2.i);
class C System.out.println(d2.j);
{ }
int i; }
static int j; Output:
C() 10
{ 20
i=10; 100
j=20; 200
} 154. Program
C(int k,int m) class A
{ {
i=k; int i;
j=m; }
} class Manager
void print() {
{ public static void main(String args[])
System.out.println(i); {
System.out.println(j); A a1 = new A(10);
} System.out.println(a1.i);
public static void main(String args[]) }
{ }
C c1 = new C(); Output:
C c2 = new C(30,40); Compile Time Error
c1.print(); 155. Program
c2.print(); class B
} {
} int i;
Output: B(int i)
10 {
40 this.i=i;
30 }
40 }
153. Program class Manager1
class D {
{ public static void main(String args[])
int i; {
38
Lara Technologies RSTechnologies
B b1 = new B(); System.out.println(m1.i);
System.out.println(b1.i); }
} }
} Output:
Output: Compile Time Error
Compile Time Error 160. Program
156. Program class D
class Manager3 {
{ D()
public static void main(String args[]) {
{ System.out.println("Hello");
System.out.println(i); }
} }
} class Manager8
Output: {
Compile Time Error public static void main(String args[])
157. Program {
class Manager5 D d1 = new D();
{ System.out.println("-----------");
static int i; D d2 = new D();
public static void main(String args[]) System.out.println("-----------");
{ D d3 = new D();
System.out.println(i); System.out.println("-----------");
} }
} }
Output: Output:
Compile Success Hello
0 -----------
158. Program Hello
class Manager6 -----------
{ Hello
int i; -----------
public static void main(String args[]) 161. Program
{ class E
Manager6 m1 = new Manager6(); {
System.out.println(m1.i); E()
} {
} System.out.println(1);
Output: }
Compile Success E(int i)
0 {
159. Program this();
class Manager7 System.out.println(2);
{ }
int i; }
public static void main(String args[]) class Manager10
{ {
Manager6 m1 = new Manager6(10); public static void main(String args[])
39
Lara Technologies RSTechnologies
{ System.out.println(2);
E e1 =new E(); }
System.out.println("---------"); G(int i)
E e2 =new E(10); {
} this(i,i);
} System.out.println(3);
Output: }
1 }
---------
1 class Manager12
2 {
162. Program public static void main(String args[])
class F {
{ G g1 =new G();
F() System.out.println("----------");
{ G g2 =new G(1);
this(10); System.out.println("----------");
System.out.println(1); G g3 =new G(1,2);
} }
F(int i) }
{ Output:
System.out.println(2); 1
} ----------
} 1
class Manager11 2
{ 3
public static void main(String args[]) ----------
{ 1
F f1 =new F(); 2
System.out.println("-----------"); 164. Program
F f2 =new F(20); class Manager1
} {
} int i;
Output: public static void main(String args[])
2 {
1 Manager1 m;
----------- System.out.println(m.i);
2 }
163. Program }
class G Output:
{ Compile Time Error
G() 165. Program
{ class Manager2
System.out.println(1); {
} int i;
G(int i,int j) public static void main(String args[])
{ {
this(); Manager2 m;
40
Lara Technologies RSTechnologies
System.out.println("ends"); {
} System.out.println(m.i);
} }
Output: }
ends Output:
166. Program Compile Success
class Manager3 Run Time Error (NullPointerException)
{ 170. Program
int i; class Manager7
public static void main(String args[]) {
{ int i;
Manager3 m =null; Manager7 m;
System.out.println(m.i); public static void main(String args[])
} {
} Manager7 m= null;
Output: System.out.println(m.m.i);
Compile Success }
Run Time Error(java.lang.NullPointerException) }
167. Program Output:
class Manager4 Compile Success
{ Run Time Error(java.lang.NullPointerException)
int i; 171. Program
public static void main(String args[]) class Manager8
{ {
Manager4 m =new Manager4(); int i;
System.out.println(m.i); Manager8 m;
} public static void main(String args[])
} {
Output: Manager8 m=null;
0 System.out.println(m.m.m.m.i);
168. Program }
class Manager5 }
{ Output:
int i; Compile Success
Manager5 m; Run Time Error(java.lang.NullPointerException)
public static void main(String args[]) 172. Program
{ class A
System.out.println(m.i); {
} int i;
} A a;
Output: }
Compile Time Error class Manager
169. Program {
class Manager6 public static void main(String args[])
{ {
int i; A a1=null;
static Manager6 m; System.out.println(a1.a.a.a.a.a.a.i);
public static void main(string args[]) }
41
Lara Technologies RSTechnologies
} 175. Program
Output: class C
Compile Success {
Run Time Error (java.lang.NullPointerException) int i;
173. Program void print(C c1,C c2)
class A {
{ System.out.println(i);
int i; System.out.println(this.i);
A a; System.out.println(c1.i);
} System.out.println(c2.i);
class Manager9 }
{ }
public static void main(String args[]) class Manager11
{ {
A a1=new A(); public static void main(String args[])
test(a1); {
} C c1 =new C();
static void test(A a1) C c2 =new C();
{ C c3 =new C();
System.out.println(a1.i); c1.i=10;
} c2.i=20;
} c3.i=30;
Output: c1.print(c2,c3);
0 c1.print(c1,c2);
174. Program }
class B }
{ Output:
int i; 10
void test(B b) 10
{ 20
System.out.println(b.i); 30
System.out.println(i); 10
} 10
} 10
class Manager10 20
{ 176. Program.
public static void main(String args[]) class A1
{ {
B b1 =new B(); int i;
b1.i=100; A1()
B b2 =new B(); {
b2.i=200; System.out.println(1);
b2.test(b1); }
} }
} class B extends A1
Output: {
100 B(int i)
200 {
42
Lara Technologies RSTechnologies
System.out.println(2); }
this.i=i; }
}
} class D extends C
class Manager12 {
{ D()
public static void main(String args[]) {
{ System.out.println(2);
B b1 =new B(20); }
System.out.println(b1.i); }
} class Manager1
} {
Output: public static void main(String args[])
1 {
2 D d1 =new D();
20 }
177. Program }
class A Output:
{ Compile Time Error
A(int i) 179. Program
{ class E
System.out.println(1); {
} E(double d)
} {
System.out.println(1);
class B extends A }
{ }
B(int i) class F extends E
{ {
System.out.println(2); F()
} {
} E(10.0);
class Manager }
{ }
public static void main(String args[]) class Manager2
{ {
A a1= new A(10); public static void main(String args[])
B b1= new B(20); {
} F f1= new F();
} }
Output: }
Compile Time Error
178. Program Output:
class C Compile Time Error
{ 180. Program
C(int i)
{ class G
System.out.println(1); {
43
Lara Technologies RSTechnologies
G(boolean b) class I
{ {
System.out.println(1); I(char c1)
} {
} System.out.println(1);
class H extends G }
{ }
} class J extends I
{
class Manager3 J()
{ {
public static void main(String args[]) System.out.println(2);
{ }
System.out.println("done"); J(char c1)
} {
} System.out.println(3);
Output: }
Compile Time Error }
181. Program class Manager4
class G1 {
{ public static void main(String args[])
G1(boolean b) {
{ System.out.println("done");
System.out.println(b); }
} }
} Output:
class H1 extends G1 Compile Time Error
{ 183. Program
H1() class K
{ {
super(true); K()
System.out.println(1); {
} System.out.println(1);
} }
}
class Manager3 class L extends K
{ {
public static void main(String args[]) L()
{ {
H1 h1 = new H1(); System.out.println(2);
System.out.println("done"); }
} }
} class M extends L
Output: {
true M()
1 {
done System.out.println(3);
182. Program super();
}
44
Lara Technologies RSTechnologies
} System.out.println(2);
class Manager5 }
{ P(char c1)
public static void main(String args[]) {
{ this();
M m= new M(); System.out.println(3);
} }
} }
Output: class Manager7
Compile Time Error {
call to super must be first statement in constructor public static void main(String args[])
184. Program {
class N P p1= new P();
{ }
N() }
{ Output:
this(10); Compile Time Error
System.out.println(1); recursive constructor invocation
} 186. Program
N(int i) class Q
{ {
this(); Q()
System.out.println(2); {
} this();
} }
class Manager6 }
{ class Manager8
public static void main(String args[]) {
{ public static void main(String args[])
System.out.println("done"); {
} Q q1= new Q();
} }
Output: }
Compile Time Error Output:
recursive constructor invocation Compile Time Error
185. Program recursive constructor invocation
class O 187. Program
{ class Q1
O() {
{ Q1(int i)
System.out.println(1); {
} this(10);
} }
class P extends O }
{ class Manager9
P() {
{ public static void main(String args[])
this('a'); {
45
Lara Technologies RSTechnologies
Q1 q1= new Q1(20); }
} U(int i)
} {
Output: System.out.println(2);
Compile Time Error this();
recursive constructor invocation }
}
Output:
Compile Time Error
188. Program call to this must be first statement in constructor
46
Lara Technologies RSTechnologies
{ {
W w =new W(); System.out.println(2);
w.W(); return x;
} }
} }
Output:
1 class Manager13
192. Program {
class X public static void main(String args[])
{ {
X x; X x1= new X();
X() System.out.println("Main Method");
{ x1.x();
this.x=x; }
} }
X x(X x) Output:
{ 1
return x; Main Method
} 2
X x() 194. Program
{ class X
return x; {
} X x;
} X(int x)
{
class Manager13 System.out.println(1);
{ System.out.println(x);
public static void main(String args[]) }
{ int x(int x)
X x1= new X(); {
System.out.println("Main Method"); return x;
} }
} X x()
Output: {
Main Method System.out.println(2);
193. Program return x;
class X }
{ }
X x;
X() class Manager13
{ {
System.out.println(1); public static void main(String args[])
} {
X x(X x) X x1= new X(11);
{ System.out.println("Main Method");
return x; x1.x(22);
} System.out.println(x1.x);
X x() }
}
47
Lara Technologies RSTechnologies
Output: System.out.println("ObjectCreated");
1 }
11 }
Main Method
null class Manager
195. Program {
class A public static void main(String args[])
{ {
A() A a1 = new A();
{ A a2 = new A(10);
System.out.println("ObjectCreated"); A a3 = new A(10,20);
} }
A(int i) }
{ Output:
System.out.println("ObjectCreated"); Object Created
} Object Created
A(int i,int j) Object Created
{ 197. Program
System.out.println("ObjectCreated"); class A1
} {
} static int p;
A1()
class Manager {
{ p++;
public static void main(String args[]) }
{ A1(int i)
A a1 = new A(); {
A a2 = new A(10); p++;
A a3 = new A(10,20); }
} A1(int i,int j)
} {
Output: p++;
Object Created }
Object Created }
Object Created class Manager2
196. Program {
class A public static void main(String args[])
{ {
A() A1 a1 = new A1();
{ A1 a2 = new A1(10);
} A1 a3 = new A1(10,20);
A(int i) System.out.println(a3.p);
{ }
} }
A(int i,int j) Output:
{ 3
} 198. Program
{ class A1
48
Lara Technologies RSTechnologies
{ public static void main(String args[])
static int p; {
A1() D d1 = new D();
{ System.out.println("--------");
} D d2 = new D(100);
A1(int i) System.out.println(d1.i+":"+d2.i);
{ }
} }
A1(int i,int j) Output:
{ 200
} --------
{ 200
p++; 10:100
} 200. Program
} class F
{
class Manager2 F()
{ {
public static void main(String args[]) System.out.println(1);
{ }
A1 a1 = new A1(); F(int i)
A1 a2 = new A1(10); {
A1 a3 = new A1(10,20); this();
System.out.println(a3.p); System.out.println(2);
} }
} {
System.out.println(3);
Output: }
3 }
199. Program class Manager4
class D {
{ public static void main(String args[])
int i; {
D(int i) F f1 = new F();
{ System.out.println("-------");
System.out.println(this.i); F f2 = new F(10);
this.i=i; }
} }
D() Output:
{ 3
System.out.println(i); 1
i=10; -------
} 3
{ 1
i=200; 2
} 201. Program
} class H
class Manager3 {
{
49
Lara Technologies RSTechnologies
int i,j,k; this.i=i++;
H(int i) this.j=j++;
{ this.k=k++;
i++; }
} }
H(int i,int j) class Manager5
{ {
i++; public static void main(String args[])
j++; {
} H h1 =new H(1);
H(int i,int j,int k) H h2 =new H(1,2);
{ H h3 =new H(1,2,3);
i++; System.out.println(h1.i);
j++; System.out.println(h2.i+":"+h2.j);
k++; System.out.println(h3.i+":"+h3.j+":"
} +h3.k);
} }
class Manager5 }
{ Output:
public static void main(String args[]) 1
{ 1:2
H h1 =new H(1); 1:2:3
H h2 =new H(1,2); 203. Program
H h3 =new H(1,2,3); public class Manager2
System.out.println(h1.i); {
System.out.println(h2.i+":"+h2.j); private Manager2()
System.out.println(h3.i+":"+h3.j+":" {
+h3.k); System.out.println("hello");
} }
} private void Manager()
Output: {
0 System.out.println("hai");
0:0 }
0:0:0 public static void main(String[] args)
202. Program {
class H new Manager2();
{ }
int i,j,k; }
H(int i) Output:
{ hello
this.i=i++; 204. Program
} public class Manager2
H(int i,int j) {
{ private Manager2()
this.i=i++; {
this.j=j++; System.out.println("privateconstruct
} or");
H(int i,int j,int k) return;
{
50
Lara Technologies RSTechnologies
} {
private void Manager() static
{ {
System.out.println("hai"); System.out.println(1);
} }
public static void main(String[] args) {
{ System.out.println(2);
new Manager2(); }
} T()
} {
Output: System.out.println(3);
private constructor }
205. Program }
public class Manager2 public class Manager extends T
{ {
private Manager2(int i) Manager()
{ {
System.out.println("i"); System.out.println(4);
} }
Manager2(int j) static
{ {
System.out.println("j"); System.out.println(5);
} }
public static void main(String[] args) {
{ System.out.println(6);
new Manager2(1); }
} public static void main(String args[])
} {
Output: new Manager();
Compile Time Error }
Manager2(int) is already defined in Manager2 }
206. Program Output:
public class Manager2 1
{ 5
Manager2 mgr=new Manager2(); 2
Manager2() 3
{ 6
System.out.println(1); 4
} 208. Program
public static void main(String[] args) public class Manager
{ {
new Manager2(); Manager(Manager m)
} {
} super();
Output: System.out.println(1);
Compile Time Error }
207. Program public static void main(String args[])
class T {
new Manager(new Object());
51
Lara Technologies RSTechnologies
} class Manager
} {
Output: public static void main(String[] args)
Compile Time Error {
constructor Manager(java.lang.Object)
209. Program }
class A }
{ Output:
void test() compile success
{ 212. Program
System.out.println("Test Method"); abstract class B
} {
} abstract void test()
class Manager {
{
public static void main(String args[]) }
{ }
A a1=new A(); Output:
a1.test(); Compile Time Error
} abstract methods cannot have a body
} 213. Program
Output: class C
Test Method {
210. Program void test()
package com.lara; {
class A
{ }
int i,j; }
abstract void test(); Output:
} Compile Success
class Manager 214. Program
{ abstract class D
public static void main(String[] args) {
{ abstract void test();
}
} Output:
} Compile Success
Output: 215. Program
CTE abstract class E
abstract Method test in type A can only be defined {
by an abstract class. void test()
211. Program {
package com.lara;
abstract class A }
{ }
int i,j; Output:
abstract void test();
} Compile success
52
Lara Technologies RSTechnologies
216. Program abstract void test(int i);
package com.lara; void test(double d)
abstract class A {
{
} }
abstract void test(char c);
class Manager extends A }
{ Output:
public static void main(String[] args) compile success
{ 220. Program
abstract class H
} {
} void test()
Output: {
Compile success.
217. Program }
abstract class F abstract void test();
{ }
abstract void test1(); Output:
void test2() CTE
{ 221. Program
package com.lara;
} abstract class A
abstract void test3(); {
} abstract void test1();
Output: }
Compile Success abstract class B extends A
218. Program {
package com.lara; void test1()
class A {
{
} }
abstract class Manager extends A }
{ class Manager
public static void main(String[] args) {
{ public static void main(String[] args)
{
}
} }
Output: }
Compile success. Output:
219. Program Compile success.
abstract class G 222. Program
{ package com.lara;
void test() abstract class A
{ {
abstract void test1();
} }
53
Lara Technologies RSTechnologies
abstract class B extends A }
{ class B extends A
{
}
class C extends B void test1()
{ {
void test1() System.out.println("test()defined");
{ }
System.out.println("hello"); }
} class Manager
} {
class Manager public static void main(String[] args)
{ {
public static void main(String[] args) B b1 = new B();
{ b1.test2();
}
} }
} Output:
Output: CTE
Compile success. The method test2() is undifined for the type B
223. Program 225. Program.
package com.lara; package com.lara;
abstract class A abstract class A
{ {
abstract void test1(); abstract void test2();
} }
class B extends A class B extends A
{ {
void test1()
{ void test1()
System.out.println("test()defined"); {
} System.out.println("test()defined");
} }
class Manager }
{ class Manager
public static void main(String[] args) {
{ public static void main(String[] args)
B b1 = new B(); {
b1.test1(); B b1 = new B();
} b1.test2();
} }
Output: }
test()defined Output:
224. Program CTE
package com.lara; The type B must implement the inherited abstract
abstract class A method A.test2()
{ 226. Program
abstract void test1(); package com.lara;
54
Lara Technologies RSTechnologies
abstract class A {
{ System.out.println("Inside static
abstract void test2(); method of abstract class");
} }
class B extends A public static void main(String[] args)
{ {
void test2()
{ }
System.out.println("test()defined"); }
} Output:
} Compile success
class Manager 229. Program
{ package com.lara;
public static void main(String[] args)
{ abstract class A
A a1 = new A(); {
a1.test2(); int i;
} abstract void test2();
} abstract void disp();
Output: }
CTE class Manager extends A
Cannot instantiate the type A(we cannot creat object {
to abstract class ) void test()
227. Program {
package com.lara; System.out.println("test()defined");
abstract class Manager }
{
int i; void disp()
abstract void test2(); {
static void disp() System.out.println("Inside static
{ method of abstract class");
System.out.println("Inside static }
method of abstract class"); public static void main(String[] args)
} {
public static void main(String[] args) Manager b1= new Manager();
{ b1.test2();
Manager.disp();
} }
} }
Output: Output:
Inside static method of abstract class Compile Error
228. Program 230. Program
package com.lara; package com.lara;
abstract class Manager abstract class A
{ {
int i; int i;
abstract void test2(); abstract void test2();
static void disp() abstract void disp();
55
Lara Technologies RSTechnologies
} }
class Manager extends A }
{ Output:
Compile Time Error
void test2() 233. Program
{ class L
System.out.println("test()defined"); {
} private void test()
{
void disp() }
{ int test()
System.out.println("Inside static {
method of abstract class"); return 100;
} }
public static void main(String[] args) }
{ Output:
CTE
Manager b1= new Manager(); 234. Program
b1.test1(); class L
{
} private void test()
} {
Output: }
CTE int test1()
The method test1() is undefined for the type {
Manager. return 100;
231. Program }
class I }
{ Output:
void test() Compile success.
{ 235. Program
} abstract class A
int test(int a) {
{ void test()
return 100; {
} }
} abstract void test(int i);
Output: }
compile success class B extends A
232. Program {
class J void test(int i)
{ {
void test()
{ }
} }
int test() class C extends B
{ {
return 100; void test(int i)
56
Lara Technologies RSTechnologies
{ class T extends S
{
} }
} class Manager
Output: {
compile success public static void main(String[] args)
236. Program {
abstract class X
{ }
abstract void test(); }
} Output:
class Y extends X Compile success.
{ 239. Program
void test() package com.lara;
{ abstract class G
System.out.println("test"); {
} abstract static void test()
} {
class Manager
{ System.out.println("A");
public static void main(String args[])
{ }
Y y1 =new Y(); }
y1.test(); public class Manager1
} {
} public static void main(String[] args)
Output: {
test System.out.println("Manager");
237. Program }
abstract class R }
{ Output:
} Compile Time Error
abstract class S extends R 240. Program
{ package com.lara;
} abstract class G
class Z extends S {
{ static void test()
} {
Output: System.out.println("A");
Compile Time Error
238. Program }
package com.lara;
class R }
{ public class Manager1
} {
class S extends R public static void main(String[] args)
{ {
} System.out.println("Manager");
57
Lara Technologies RSTechnologies
} abstract void test();
}
Output: }
Manager
241. Program public class Manager1
package com.lara; {
abstract class G public static void main(String[] args)
{ {
static void test() System.out.println("Manager");
{ }
System.out.println("G"); }
Output:
} Manager
} 244. Program
public class Manager1 package com.lara;
{ public abstract class Manager1
public static void main(String[] args) {
{ public static void main(String[] args)
System.out.println(G.test()); {
} System.out.println("Manager");
} }
Output: }
CTE Output:
242. Program Manager
package com.lara; 245. Program
abstract class G package com.lara;
{
static void test() abstract class G{
{ void test()
{
System.out.println("G"); System.out.println("A");
}
} }
58
Lara Technologies RSTechnologies
246. Program }
package com.lara; }
abstract class G Output:
{ CTE
void test() The class G can have either abstract or final not
{ both.
System.out.println("A"); 248. Program
} package com.lara;
} final class G
{
public class Manager1 extends G
{ void test()
{
void test() System.out.println("A");
{ }
System.out.println("Manager"); }
}
public static void main(String[] args) abstract class Manager1 extends G
{ {
void test()
G a1 = new Manager1(); {
System.out.println("Manager");
((G)a1).test(); }
} public static void main(String[] args)
} {
Output:
Manager. }
247. Program }
package com.lara; Output:
final abstract class G CTE
{ Manager1 cannot be sub class to final class G.
249. Program
void test() package com.lara;
{ abstract interface G
System.out.println("A"); {
}
} void test();
}
public class Manager1 extends G public class Manager1 extends G
{ {
void test()
{ void test()
System.out.println("Manager"); {
} System.out.println("Manager");
public static void main(String[] args) }
{ public static void main(String[] args)
Manager1 a1 = new Manager1(); {
a1.test();
59
Lara Technologies RSTechnologies
Manager1 a1 = new Manager1(); Output:
a1.test(); Test Method
252. Program
} class A
} {
Output: void test()
CTE {
250. Program System.out.println("Test Method");
package com.lara; }
abstract class G }
{ class Manager
{
void test() public static void main(String args[])
{ {
} A a1=new A();
} a1.test();
final class Manager1 extends G }
{ }
void test() Output:
{ Test Method
System.out.println("Manager"); 253. Program
} package com.lara;
public static void main(String[] args) class A
{ {
int i,j;
Manager1 a1 = new Manager1(); abstract void test();
a1.test(); }
} class Manager
} {
Output: public static void main(String[] args)
Compile success {
Manager
251. Program }
class A }
{ Output:
void test() CTE
{ abstract Method test in type A can only be defined
System.out.println("Test Method"); by an abstract class.
} 254. Program
} package com.lara;
class Manager abstract class A
{ {
public static void main(String args[]) int i,j;
{ abstract void test();
A a1=new A(); }
a1.test(); class Manager
} {
} public static void main(String[] args)
60
Lara Technologies RSTechnologies
{ {
}
}
} class Manager extends A
Output: {
compile success public static void main(String[] args)
255. Program {
abstract class B
{ }
abstract void test() }
{ Output:
Compile success.
} 260. Program
abstract class F
} {
Output: abstract void test1();
Compile Time Error void test2()
abstract methods cannot have a body {
256. Program
class C }
{ abstract void test3();
void test() }
{ Output:
Compile Success
} 261. Program
} package com.lara;
Output: class A
Compile Success {
257. Program }
abstract class D
{ abstract class Manager extends A
abstract void test(); {
} public static void main(String[] args)
Output: {
Compile Success
258. Program }
abstract class E }
{ Output:
void test() Compile success.
{ 262. Program
abstract class G
} {
} void test()
Output: {
Compile success
259. Program }
package com.lara; abstract void test(int i);
abstract class A void test(double d)
61
Lara Technologies RSTechnologies
{ {
} }
abstract void test(char c); class C extends B
} {
Output: void test1()
compile success {
263. Program System.out.println("hello");
abstract class H }
{ }
void test() class Manager
{ {
public static void main(String[] args)
} {
abstract void test();
} }
Output: }
CTE Output:
264. Program Compile success.
package com.lara; 266. Program
abstract class A package com.lara;
{ abstract class A
abstract void test1(); {
} abstract void test1();
abstract class B extends A }
{ class B extends A
void test1() {
{
void test1()
} {
} System.out.println("test()defined");
class Manager }
{ }
public static void main(String[] args) class Manager
{ {
public static void main(String[] args)
} {
} B b1 = new B();
b1.test1();
Output: }
Compile success. }
265. Program Output:
package com.lara; test()defined
abstract class A 267. Program
{ package com.lara;
abstract void test1(); abstract class A
} {
abstract class B extends A abstract void test1();
62
Lara Technologies RSTechnologies
} abstract class A
class B extends A {
{ abstract void test2();
}
void test1() class B extends A
{ {
System.out.println("test()defined");
} void test2()
} {
class Manager System.out.println("test()defined");
{ }
public static void main(String[] args) }
{ class Manager
B b1 = new B(); {
b1.test2(); public static void main(String[] args)
} {
} A a1 = new A();
Output: a1.test2();
CTE }
The method test2() is undifined for the type B }
268. Program Output:
package com.lara; CTE
abstract class A Cannot instantiate the type A(we cannot creat object
{ to abstract class )
abstract void test2(); 270. Program
} package com.lara;
class B extends A abstract class Manager
{ {
int i;
void test1() abstract void test2();
{ static void disp()
System.out.println("test()defined"); {
} System.out.println("Inside static
} method of abstract class");
class Manager }
{ public static void main(String[] args)
public static void main(String[] args) {
{
B b1 = new B(); Manager.disp();
b1.test2(); }
} }
} Output:
Output: Inside static method of abstract class
CTE 271. Program
The type B must implement the inherited abstract package com.lara;
method A.test2() abstract class Manager
269. Program {
package com.lara; int i;
63
Lara Technologies RSTechnologies
abstract void test2(); abstract void test2();
static void disp() abstract void disp();
{ }
System.out.println("Inside static class Manager extends A
method of abstract class"); {
}
public static void main(String[] args) void test2()
{ {
System.out.println("test()defined");
} }
}
Output: void disp()
Compile success {
System.out.println("Inside static
272. Program method of abstract class");
package com.lara; }
abstract class A public static void main(String[] args)
{ {
int i;
abstract void test2(); Manager b1= new Manager();
abstract void disp(); b1.test1();
}
class Manager extends A }
{ }
void test() Output:
{ CTE
System.out.println("test()defined"); The method test1() is undefined for the type
} Manager.
274. Program
void disp() class I
{ {
System.out.println("Inside static void test()
method of abstract class"); {
} }
public static void main(String[] args) int test(int a)
{ {
Manager b1= new Manager(); return 100;
b1.test2(); }
}
} Output:
} compile success
Output: 275. Program
Compile Error class J
273. Program {
package com.lara; void test()
abstract class A {
{
int i; }
64
Lara Technologies RSTechnologies
int test() }
{ }
return 100; class C extends B
} {
} void test(int i)
Output: {
Compile Time Error
test() is already defined in J }
276. Program }
class L Output:
{ compile success
private void test() 279. Program
{ abstract class X
} {
int test() abstract void test();
{ }
return 100; class Y extends X
} {
} void test()
Output: {
CTE System.out.println("test");
277. Program }
class L }
{ class Manager
private void test() {
{ public static void main(String args[])
} {
int test1() Y y1 =new Y();
{ y1.test();
return 100; }
} }
} Output:
Output: test
Compile success. 280. Program
278. Program abstract class R
abstract class A {
{ }
void test() abstract S extends R
{ {
}
} class Z extends S
abstract void test(int i); {
} }
class B extends A Output:
{ Compile Time Error
void test(int i) 281. Program
{ package com.lara;
class R
65
Lara Technologies RSTechnologies
{ public class Manager1
} {
class S extends R public static void main(String[] args)
{ {
} System.out.println(G.test());
class T extends S }
{ }
} Output:
class Manager CTE
{ 284. Program
public static void main(String[] args) package com.lara;
{ abstract class G
{
} static void test()
} {
Output:
Compile success. System.out.println("G");
282. Program }
package com.lara;
abstract class G }
{ public class Manager1
static void test() {
{ public static void main(String[] args)
System.out.println("A"); {
G.test();
} }
}
} Output:
public class Manager1 G
{ 285. Program
public static void main(String[] args) package com.lara;
{ abstract class G
System.out.println("Manager"); {
} abstract void test();
}
Output: }
Manager
283. Program public class Manager1
package com.lara; {
abstract class G public static void main(String[] args)
{ {
static void test() System.out.println("Manager");
{ }
System.out.println("G"); }
Output:
} Manager
286. Program
} package com.lara;
66
Lara Technologies RSTechnologies
public abstract class Manager1 {
{ System.out.println("Manager");
public static void main(String[] args) }
{ public static void main(String[] args)
System.out.println("Manager"); {
}
} G a1 = new Manager1();
Output:
Manager ((G)a1).test();
287. Program }
package com.lara; }
abstract class G Output:
{ Manager.
void test() 289. Program
{ package com.lara;
System.out.println("A"); final abstract class G
} {
}
void test()
public class Manager1 extends G {
{ System.out.println("A");
void test() }
{ }
System.out.println("Manager");
} public class Manager1 extends G
public static void main(String[] args) {
{ void test()
G a1 = new Manager1(); {
a1.test(); System.out.println("Manager");
} }
} public static void main(String[] args)
{
Output: Manager1 a1 = new Manager1();
Manager a1.test();
288. Program }
package com.lara; }
abstract class G
{ Output:
void test() CTE
{ The class G can have either abstract or final not
System.out.println("A"); both.
} 290. Program
} package com.lara;
final class G
public class Manager1 extends G {
{
void test()
void test() {
67
Lara Technologies RSTechnologies
System.out.println("A"); {
} }
} }
abstract class Manager1 extends G
{ final class Manager1 extends G
void test() {
{ void test()
System.out.println("Manager"); {
} System.out.println("Manager");
public static void main(String[] args) }
{ public static void main(String[] args)
{
}
} Manager1 a1 = new Manager1();
Output: a1.test();
CTE
Manager1 cannot be sub class to final class G. }
291. Program }
package com.lara; Output:
abstract interface G Compile success
{
INTERFACES
void test();
} 293. Program
interface A
public class Manager1 extends G {
{ void test1();
}
void test()
{ interface B extends A
System.out.println("Manager"); {
} void test2();
public static void main(String[] args) }
{ class C implements B
{
Manager1 a1 = new Manager1(); public void test1()
a1.test(); {
System.out.println("test1");
} }
} public void test2()
Output: {
CTE System.out.println("test2");
292. Program }
package com.lara; }
abstract class G class Manager
{ {
public static void main(String args[])
void test() {
C c1=new C();
68
Lara Technologies RSTechnologies
c1.test1(); double
c1.test2(); 295. Program
} interface A
} {
Output: void test1();
test1 }
test2
294. Program abstract class B
interface A {
{ public abstract void test1();
void test1(); }
} class C extends B implements A
interface B {
{ public void test1()
void test1(int i); {
} System.out.println("test");
interface C extends A,B }
{ }
void test1(double d); class Manager
} {
class D implements A,B,C public static void main(String args[])
{ {
public void test1() C c1 =new C();
{ c1.test1();
System.out.println("test"); }
} }
public void test1(int k) Output:
{ test
System.out.println("int"); 296. Program
} class E
public void test1(double d) {
{ public void test1()
System.out.println("double"); {
} System.out.println("super-E");
}
} }
class Manager interface B
{ {
public static void main(String args[]) void test1();
{ }
D d1 =new D(); class C extends E implements B
d1.test1(); {
d1.test1(10); }
d1.test1(100.20); class Manager
} {
} public static void main(String args[])
Output: {
test C c1=new C();
int
69
Lara Technologies RSTechnologies
c1.test1(); System.out.println("test2-B");
} }
} }
Output: interface C
super-E {
297. Program void test1();
interface A void test2();
{ }
void test1(); class D extends B implements C
} {
class B }
{ class Manager
public void test1() {
{ public static void main(String args[])
System.out.println("test of B"); {
} D d1=new D();
} d1.test1();
class C extends B d1.test2();
{ }
} }
class D extends C Output:
{ test1-A
} test2-B
class E extends D 299. Program
{ interface A
} {
class Manager void test1();
{ }
public static void main(String args[]) interface B extends A
{ {
E e1=new E(); void test2();
e1.test1(); }
} class C implements B
} {
Output: public void test1()
test of B {
298. Program System.out.println("test1");
class A }
{ public void test2()
public void test1() {
{ System.out.println("test2");
System.out.println("test1-A"); }
} }
} class Manager
class B extends A {
{ public static void main(String args[])
public void test2() {
{ C c1=new C();
c1.test1();
70
Lara Technologies RSTechnologies
c1.test2(); interface A
} {
} void test1();
Output: }
test1
test2 abstract class B
300. Program {
interface A public abstract void test1();
{ }
void test1(); class C extends B implements A
} {
interface B public void test1()
{ {
void test1(int i); System.out.println("test");
} }
interface C extends A,B }
{ class Manager
void test1(double d); {
} public static void main(String args[])
class D implements A,B,C {
{ C c1 =new C();
public void test1() c1.test1();
{ }
System.out.println("test"); }
} Output:
public void test1(int k) Test
{ 302. Program
System.out.println("int"); class E
} {
public void test1(double d) public void test1()
{ {
System.out.println("double"); System.out.println("super-E");
} }
} }
class Manager interface B
{ {
public static void main(String args[]) void test1();
{ }
D d1 =new D(); class C extends E implements B
d1.test1(); {
d1.test1(10); }
d1.test1(100.20); class Manager
} {
} public static void main(String args[])
Output: {
test C c1=new C();
int c1.test1();
double }
301. Program }
71
Lara Technologies RSTechnologies
Output: interface C
super-E {
303. Program void test1();
interface A void test2();
{ }
void test1(); class D extends B implements C
} {
class B }
{ class Manager
public void test1() {
{ public static void main(String args[])
System.out.println("test of B"); {
} D d1=new D();
} d1.test1();
class C extends B d1.test2();
{ }
} }
class D extends C Output:
{ test1-A
} test2-B
class E extends D 305. Program
{ abstract interface A
} {
class Manager void test();
{ }
public static void main(String args[]) public class Manager extends A
{ {
E e1=new E(); void test()
e1.test1(); {
} System.out.println("Manager");
} }
Output: public static void main(String args[])
test of B {
304. Program Manager a1=new Manager();
class A a1.test();
{ }
public void test1() }
{ Output:
System.out.println("test1-A"); Compile Time Error
} 306. Program
} interface A
class B extends A {
{ void test();
public void test2() }
{ public class Manager extends A
System.out.println("test2-B"); {
} public void test()
} {
72
Lara Technologies RSTechnologies
System.out.println("Manager"); interface A
} {
public static void main(String[] args) void test();
{ }
Manager m1=new Manager(); class Manager implements A
m1.test(); {
} void test()
} {
Output: System.out.println("Manager");
Compile Time Error }
307. Program public static void main(String[] args) {
interface A A a1=new A();
{ a1.test();
void test(); }
} }
class Manager implements A Output:
{ Compile Time Error
public void test() 310. Program
{ interface A
System.out.println("Manager"); {
} void test();
public static void main(String[] args) }
{ class Manager implements A
Manager a1=new Manager(); {
a1.test(); protected void test()
} {
} System.out.println("Manager");
Output: }
Manager public static void main(String[] args)
308. Program {
interface A A a1=new A();
{ a1.test();
void test(); }
} }
class Manager implements A Output:
{ Compile Time Error
void test() 311. Program
{ interface A
System.out.println("Manager"); {
} int i=0;
public static void main(String[] args) { void test();
Manager a1=new Manager(); }
a1.test(); public class Manager implements A
} {
} public void test()
Output: {
Compile Time Error System.out.println("Manager");
309. Program }
73
Lara Technologies RSTechnologies
public static void main(String[] args) {
{ A a1=new Manager();
System.out.println(A.i); System.out.println(a1.i);
} }
} }
Output: Output:
0 Compile Success
312. Program 0
interface A 314. Program
{ interface A
int i=0; {
} int i=0;
interface B extends A }
{ interface B extends A
int i=1; {
} int i=1;
interface C extends B }
{ interface C extends B
int i=2; {
} int i=2;
public class Manager implements A }
{ class Manager implements A
int i=3; {
public static void main(String[] args) int i=3;
{ public static void main(String[] args)
A a1=new Manager(); {
System.out.println(a1.i); C c1=new Manager();
} System.out.println(c1.i);
} }
Output: }
0 Output:
313. Program Compile Time Error
interface A 315. Program
{ interface A
int i=0; {
} int i=0;
interface B extends A }
{ interface B extends A
int i=1; {
} int i=1;
interface C extends B }
{ interface C extends B
int i=2; {
} int i=2;
class Manager implements A }
{ class Manager implements A
int i=3; {
public static void main(String[] args) int i=3;
74
Lara Technologies RSTechnologies
public static void main(String[] args) int i=3;
{ public static void main(String[] args)
C c1=(C)new Manager(); {
System.out.println(c1.i); C c1=new Manager();
} System.out.println(c1.i);
} A a1=new Manager();
Output: System.out.println(a1.i);
Compile Success B b1=new Manager();
ClassCastException will occur System.out.println(b1.i);
316. Program
interface A }
{ }
int i=0; Output:
} 2
interface B extends A 0
{ 1
int i=1; 318. Program
} interface A
interface C extends B {
{ int i=0;
int i=2; }
} interface B extends A
class Manager implements C {
{ int i=1;
int i=3; }
public static void main(String[] args) interface C extends B
{ {
C c1=(C)new Manager(); int i=2;
System.out.println(c1.i); }
} class Manager implements A,B,C
} {
Output: int i=3;
2 public static void main(String[] args)
317. Program {
interface A A a1=new Manager();
{ System.out.println(((C)a1).i);
int i=0; }
} }
interface B extends A Output:
{ 2
int i=1; 319. Program
} interface A
interface C extends B {
{ int i=0;
int i=2; }
} interface B extends A
class Manager implements A,B,C {
{ int i=1;
75
Lara Technologies RSTechnologies
} {
interface C extends A,B System.out.println(1);
{ }
int i=2; }
} Output:
class Manager implements A,B,C Compile Time Error
{ 323. Program
int i=3; interface A
public static void main(String[] args) {
{ public void test()
A a1=new Manager(); {
System.out.println(((B)(C)(D)a1).i); System.out.println(1);
} }
} }
Output: class B extends A
Compile Time Error {
320. Program public static void main(String[] args)
interface A {
{ void test()
void test(); {
} System.out.println(2);
class B implements A }
{ }
void test() }
{ Output:
System.out.println(1); Compile Time Error
} 324. Program
} interface A
Output: {
Compile Time Error void test();
321. Program System.out.println(1);
interface A }
{ class B extends A
void test(); {
} void test();
class B implements A System.out.println(2);
{ }
public void test() class C extends B
{ {
System.out.println(1); public static void main(String[] args)
} {
} void test()
Output: {
Compile Success System.out.println(3);
322. Program }
interface A }
{ }
public void test() Output:
76
Lara Technologies RSTechnologies
Compile Time Error class B
325. Program {
interface A void test1()
{ {
void test(); System.out.println("B");
} }
class B }
{ interface C
void test1() {
{ void test2();
System.out.println("B"); }
} class Manager implements A,C
} {
interface C public void test()
{ {
void test2(); System.out.println(1);
} }
class Manager implements A,C void test1()
{ {
void test() System.out.println(2);
{ }
System.out.println(1); public void test2()
} {
void test1() System.out.println(3);
{ }
System.out.println(2);
} public static void main(String[] args)
void test2() {
{ System.out.println("Main");
System.out.println(3); Manager m1=new Manager();
} m1.test();
m1.test1();
public static void main(String[] args) m1.test2();
{
System.out.println("Main"); }
Manager.test(); }
Manager.test1(); Output:
Manager.test2(); Main
1
} 2
} 3
Output: 327. Program
Compile Time Error interface A
326. Program {
interface A int test();
{ }
void test(); class Manager
} {
public static void main(String[] args)
77
Lara Technologies RSTechnologies
{ {
A a1=new A(); }
a1.test(); class B
} {
} public final static void test()
Output: {
Compile Time Error System.out.println("test");
328. Program }
static interface A }
{ class C extends B implements A
void test(); {
} public static void main(String[] args)
class Manager implements A {
{ new C().test();
public void test() C.test();
{ }
System.out.println("Manager"); }
} Output:
public static void main(String[] args) test
{ test
Manager m1=new Manager(); 331. Program
m1.test(); interface A
} {
} void test();
Output: }
Compile Time Error class B
329. Program {
interface A public void test()
{ {
void test(); System.out.println("test");
} }
class Manager implements A }
{ class C extends B implements A
public void test() {
{ public static void main(String[] args)
System.out.println("Manager"); {
C c1=new C();
} c1.test();
public static void main(String[] args) }
{ }
Manager m1=new Manager(); Output:
m1.test(); Test
} 332. Program
} interface A
Output: {
Manager void test();
330. Program }
interface A interface B
78
Lara Technologies RSTechnologies
{ interface A
void test(); {
} abstract int i=10;
abstract class C public abstract void test();
{ }
void test(); abstract class B implements A
} {
class D extends C implements A,B public void test()
{ {
public void test() System.out.println("test");
{ }
System.out.println("test"); public static void main(String[] args)
} {
} System.out.println(new A().i);
Output: }
Compile Time Error }
333. Program Output:
interface A Compile Time Error
{ 336. Program
void test(); interface A
} {
interface B int i;
{ public abstract void test();
void test(); }
} abstract class B implements A
abstract class C {
{ public void test()
abstract void test(); {
} System.out.println("test");
class D extends C implements A,B }
{ public static void main(String[] args)
public void test() {
{ A a1=new B();
System.out.println("test"); a1.i=20;
} System.out.println(new B().i);
} }
Output: }
Compile success Output:
334. Program Compile Time Error
interface A 337. Program
{ interface A
public static final int i=10; {
final float f=100.0f; void test();
static public String S="abc"; }
} class B
Output: {
Compile Success public void test()
335. Program {
79
Lara Technologies RSTechnologies
System.out.println("test method"); }
} Output:
} compile time error
class C extends B implements A 340. Program
{ class A
public static void main(String[] args) { {
C c1=new C(); void test()
c1.test(); {
} }
} }
Output: class B
Test method {
FINAL public void test()
{
338. Program }
class A class C
{ {
void test() public void test()
{ {
}
} }
class B extends A }
{ class D extends C
private void test() {
{ public void test()
} {
} }
Output: }
compile time error }
339. Program Output:
class A compile successfully
{ 341. Program
void test() class A
{ {
} static
} {
class B System.out.println("This is A's
{ SIB");
public void test() }
{ void test1()
} {
class C extends A System.out.println("This is in
{ test1()");
private void test() }
{ }
class B extends A
} {
} void test2()
80
Lara Technologies RSTechnologies
{ System.out.println("This is B's
System.out.println("This is in SIB");
test2()"); }
} }
static class Final
{ {
System.out.println("This is B's public static void main(String[] args)
SIB"); {
} B b = new B();
} b.test1();
class Final b.test2();
{ }
public static void main(String[] args)
{ }
B b = new B(); Output:
b.test1(); This is A's SIB
b.test2(); This is B's SIB
} This is in test1()
This is in test2()
} 343. Program
Output: class A
This is A's SIB {
This is B's SIB static
This is in test1() {
This is in test2() System.out.println("This is A's
342. Program SIB");
class A }
{ final void test1()
static {
{ System.out.println("This is in
System.out.println("This is A's test1()");
SIB"); }
} }
final void test1() class B extends A
{ {
System.out.println("This is in void test1()
test1()"); {
} System.out.println("This is in
} test1()");
class B extends A }
{
void test2() void test2()
{ {
System.out.println("This is in System.out.println("This is in
test2()"); test2()");
} }
static static
{ {
81
Lara Technologies RSTechnologies
System.out.println("This is B's }
SIB"); }
} class Final
} {
class Final public static void main(String[] args)
{ {
public static void main(String[] args) B b = new B();
{ b.test1();
B b = new B(); b.test2();
b.test1(); }
b.test2();
} }
Output:
} compile time error
Output: 345. Program
compile time error class A
344. Program {
class A int i= 12;
{ static
int i= 12; {
static System.out.println("This is A's
{ SIB");
System.out.println("i value in A"+i); }
System.out.println("This is A's void test1()
SIB"); {
} System.out.println("i value in A"+i);
void test1() System.out.println("This is in
{ test1()");
System.out.println("This is in }
test1()"); }
} class B extends A
} {
class B extends A void test1()
{ {
void test1() System.out.println("This is in
{ test1()");
System.out.println("This is in }
test1()");
} void test2()
{
void test2() System.out.println("This is in
{ test2()");
System.out.println("This is in }
test2()"); static
} {
static System.out.println("This is B's
{ SIB");
System.out.println("This is B's }
SIB"); }
82
Lara Technologies RSTechnologies
class Final }
{ }
public static void main(String[] args) class Final
{ {
B b = new B(); public static void main(String[] args)
b.test1(); {
b.test2(); B b = new B();
} b.test1();
b.test2();
} }
Output:
This is A's SIB }
This is B's SIB Output:
This is in test1() This is A's SIB
This is in test2() This is B's SIB
346. Program i value in A15
class A This is in test1()
{ This is in test1()
final int i= 15; This is in test2()
static 347. Program
{ class A
System.out.println("This is A's {
SIB"); final int i= 12;
} static
void test1() {
{ System.out.println("This is A's
System.out.println("i value in A"+i); SIB");
System.out.println("This is in }
test1()"); void test1()
} {
} System.out.println("i value in A"+i);
class B extends A System.out.println("This is in
{ test1()");
void test1() }
{ }
super.test1(); class B extends A
System.out.println("This is in {
test1()"); int j;
} void test1()
{
void test2() super.test1();
{ System.out.println("This is in B's
System.out.println("This is in test1()");
test2()"); }
}
static void test2()
{ {
System.out.println("This is B's j= i + 100;
SIB"); System.out.println("j in B class j =
83
Lara Technologies RSTechnologies
i+100" +j); System.out.println("This is in B's
System.out.println("This is in test1()");
test2()"); }
}
static void test2()
{ {
System.out.println("This is B's j= i + 100;
SIB"); System.out.println("j in B class j =
} i+100" +j);
} System.out.println("This is in
class Final test2()");
{ }
public static void main(String[] args) static
{ {
B b = new B(); System.out.println("This is B's
b.test1(); SIB");
b.test2(); }
} }
} class Final
Output: {
This is A's SIB public static void main(String[] args)
This is B's SIB {
i value in A12 B b = new B();
This is in test1() b.test1();
This is in B's test1() b.test2();
j in B class j = i+100112 }
This is in test2()
348. Program }
class A Output:
{ compile time error
final int i; 349. Program
static class A
{ {
System.out.println("This is A's final int i;
SIB"); void test1()
} {
void test1() i = 100;
{ System.out.println(i);
System.out.println("i value in A"+i); }
System.out.println("This is in }
test1()"); class Final
} {
} public static void main(String[] args)
class B extends A {
{ A a1 = new A();
int j; System.out.println(a1.i);
void test1() }
{
super.test1(); }
84
Lara Technologies RSTechnologies
Output: final int i;
compile time error void test()
350. Program {
class A System.out.println(i);
{ }
final int i = 100; {
void test() i =101;
{ }
System.out.println(i); }
} class Final
} {
class Final public static void main(String[] args)
{ {
public static void main(String[] args) A a1 = new A();
{ System.out.println(a1.i);
A a1 = new A(); }
System.out.println(a1.i);
} }
Output:
} 101
Output: 353. Program
100 class A
351. Program {
class A final int i;
{ void test()
final int i; {
{ System.out.println(i);
i =111; }
} {
void test() i =101;
{ }
System.out.println(i); }
} class Final
} {
class Final public static void main(String[] args)
{ {
public static void main(String[] args) A a1 = new A();
{ a1.i=200;
A a1 = new A(); System.out.println(a1.i);
System.out.println(a1.i); }
}
}
} Output:
Output: compile time error
111 354. Program
352. Program class A
class A {
{ final int i;
85
Lara Technologies RSTechnologies
void test() A()
{ {
i = i + 101; i= 150;
System.out.println(i); System.out.println(i);
} }
{ {
i =101; i =200;
} }
} }
class Final class Final
{ {
public static void main(String[] args) public static void main(String[] args)
{ {
A a1 = new A(); A a1 = new A();
System.out.println(a1.i); System.out.println(a1.i);
} }
} }
Output: Output:
compile time error compile time error
355. Program 357. Program
class A class A
{ {
final int i; static final int i;
A() A()
{ {
System.out.println(i); System.out.println(i);
} }
{ {
i =200; i =200;
} }
} }
class Final class Final
{ {
public static void main(String[] args) public static void main(String[] args)
{ {
A a1 = new A(); A a1 = new A();
System.out.println(a1.i); System.out.println(a1.i);
} }
}
} Output:
Output: compile time error
200 358. Program
200 class A
356. Program {
class A static final int i;
{ A()
final int i; {
86
Lara Technologies RSTechnologies
System.out.println(i); }
} class Final
static {
{ public static void main(String[] args)
i =120; {
} A a1 = new A();
} i = 123;
class Final System.out.println(a1.i);
{ }
public static void main(String[] args)
{ }
A a1 = new A(); Output:
System.out.println(a1.i); compile time error
} 361. Program
class A
} {
Output: static final int i;
120 A(int s)
120 {
359. Program i =s;
class A System.out.println(i);
{ }
static final int i;
A() }
{ class Final
i =123; {
System.out.println(i); public static void main(String[] args)
} {
A a1 = new A(12);
} System.out.println(a1.i);
class Final }
{
public static void main(String[] args) }
{ Output:
A a1 = new A(); compile time error
System.out.println(a1.i); 362. Program
} class A
} {
Output: static final int i;
compile time error void test1()
360. Program {
class A System.out.println("inside void
{ test1()" +i);
static final int i; }
A() static
{ {
System.out.println(i); i =200;
} System.out.println("inside a static
87
Lara Technologies RSTechnologies
block i" +i); {
} A a1 = new A();
A() System.out.println(a1.i);
{ a1.test1();
System.out.println("inside a a1.test2();
constructor" +i); }
} }
} Output:
class Final inside a constructor1234
{ 1234
public static void main(String[] args) inside void test1()1234
{ inside a static block i1234
A a1 = new A(); inside a static block k1234
System.out.println(a1.i); 364. Program
a1.test1(); public class Manager
} {
static final String name;
} public static void main(String[] args)
Output: {
inside a static block i 200 System.out.println(name.length());
inside a constructor 200 }
200 }
inside void test1()200 Output:
363. Program compile time error
class A 365. Program
{ public class Manager
static final int i= 1234; {
void test1() static final String name;
{ static
System.out.println("inside void {
test1()" +i); name ="lara";
} }
static void test2()
{ public static void main(String[] args)
int k = i; {
System.out.println("inside a static System.out.println(name.length());
block i" +i); }
System.out.println("inside a static }
block k" +k); Output:
} 4
A() 366. Program
{ public class Manager
System.out.println("inside a {
constructor" +i); static final String name;
} static
} {
class Final name ="lara";
{ }
public static void main(String[] args)
88
Lara Technologies RSTechnologies
static void test()
public static void main(String[] args) {
{ {
System.out.println(name); name ="lara";
} }
} }
Output: public static void main(String[] args)
lara {
367. Program System.out.println(name.length());
public class Manager
{ }
static final String name; }
static
{ Output:
name ="lara"; compile time error
} 370. Program
public class Manager
public static void main(String[] args) {
{ static final int all[];
System.out.println(name.length()); static void test()
System .out.println(name); {
{
} all = new int[10];
} }
Output: }
4 public static void main(String[] args)
lara {
368. Program System.out.println(name.length());
public class Manager
{ }
static final String name = "init"; }
static Output:
{ compile time error
name ="lara"; 371. Program
} public class Manager
{
public static void main(String[] args) static final int all[] = new int[]{0};
{ public static void main(String[] args)
System.out.println(name.length()); {
System.out.println(all.length);
}
} }
Output: }
compile time error Output:
369. Program 1
public class Manager 372. Program
{ public class Manager
static final String name; {
89
Lara Technologies RSTechnologies
static final int all[] = new int[]{0}; Output:
static compile time error
{ 375. Program
all = {0,1,3}; public class Test
} {
public static void main(String[] args) private final int id;
{ public Test(int id)
System.out.println(all.length); {
this.id = id;
} }
} public void update(int newId)
Output: {
compile time error
373. Program }
public class Manager public static void main(String[] args)
{ {
static final int all[] = new int[]{0}; Test a = new Test (42);
static a.update(69);
{ System.out.println(a.id);
all = new int[] {0,1,3}; }
} }
public static void main(String[] args) Output:
{ 42
System.out.println(all.length);
CASTING
} 376. Program
} class Manager
Output: {
compile time error static void test (double d)
374. Program {
public class Test System.out.println("double");
{ }
private final int id; public static void main(String[] args)
public Test(int id) {
{ {
this.id = id; int i= 10;
} test (i);
public void update(int newId) }
{ }
id = newId; }
} Output:
public static void main(String[] args) double
{ 377. Program
Test a = new Test (42); class Manager
a.update(69); {
System.out.println(a.id); static void test (int i)
} {
} System.out.println("Integer");
90
Lara Technologies RSTechnologies
} static void test (int i)
public static void main(String[] args) {
{ System.out.println("Integer");
{ }
int i= 10; public static void main(String[] args)
test (i); {
} {
} long l = 13.07;
} test (l);
Output: }
Integer }
378. Program }
class Manager Output:
{ Compile time error
static void test (int i) 381. Program
{ class Manager
System.out.println("Integer"); {
} public static void main(String[] args)
public static void main(String[] args) {
{ double d = test(100);
{ System.out.println("done");
byte b= 20; }
test (b); static float test(long l)
} {
} return l;
} }
Output: }
Integer
379. Program Output:
class Manager done
{ 382. Program
static void test (int i) class Manager
{ {
System.out.println("Integer"); public static void main(String[] args)
} {
public static void main(String[] args) double d = test(100);
{ System.out.println("done");
{ }
short s = 13; static long test(float f)
test (s); {
} return f;
} }
} }
Output: Output:
Integer Compile time error
380. Program 383. Program
class Manager class Manager
{ {
91
Lara Technologies RSTechnologies
public static void main(String[] args) System.out.println("done");
{ System.out.println(b);
double d = test(100); }
System.out.println("done"); static byte test(int i)
} {
static long test(long l) return i;
{ }
return l; }
} Output:
} Compile time error
Output: 387. Program
done class Manager
384. Program {
class Manager public static void main(String[] args)
{ {
public static void main(String[] args) byte b = 7/3;
{ test(b);
double d = test(100); System.out.println("done");
System.out.println("done"); System.out.println(b);
} }
static int test(float f) static byte test(byte b)
{ {
return (int) f; return b;
} }
} }
Output: Output:
done done
385. Program 2
class Manager 388. Program
{ class Manager
public static void main(String[] args) {
{ public static void main(String[] args)
double d = test(100); {
System.out.println("done"); byte b = 123/4;
} test(b);
static int test(float f) System.out.println("done");
{ System.out.println(b);
return (byte) f; }
} static double test(int b)
} {
Output: return b;
done }
386. Program }
class Manager Output:
{ done
public static void main(String[] args) 30
{ 389. Program
byte b = test(11/12); class Manager
92
Lara Technologies RSTechnologies
{ {
public static void main(String[] args) }
{ class Manager extends F
double b = 10.05; {
float f =(long)b; public static void main(String[] args)
byte c = (byte)b; {
short s =(byte)b; Manager m1 = new Manager();
System.out.println("done"); m1 = test1(m1);
System.out.println(b); System.out.println("done");
} }
} static D test1 (A a1)
Output: {
done return (D)test2(a1);
10.05 }
390. Program static C test2(Object o)
class Manager {
{ return (C)o;
static void test(double i) }
{ }
System.out.println("double"); Output:
} Compile time error
public static void main(String[] args) 392. Program
{ class A
double i = 11/2; {
test(i); }
System.out.println(i); class B extends A
} {
} }
Output: class C extends B
double {
5.0 }
391. Program class D extends C
class A {
{ }
} class E extends D
class B extends A {
{ }
} class F extends E
class C extends B {
{ }
} class Manager extends F
class D extends C {
{ public static void main(String[] args)
} {
class E extends D Manager m1 = new Manager();
{ m1 = (Manager) test1(m1);
} System.out.println("done");
class F extends E }
static D test1 (A a1)
93
Lara Technologies RSTechnologies
{ double all[] = new double[3];
return (D)test2(a1); int i1 = 100;
} byte b1=10;
static C test2(Object o) float f1= 10;
{ all[0]=i1;
return (C)o; all[1]=b1;
} all[2]=f1;
} for (int i=0;i<3; i++)
Output: {
Done
393. Program System.out.println(all[i]);
class A }
{ }
void test() }
{ Output:
System.out.println("A"); 100.0
} 10.0
} 10.0
class B extends A Class Cast exception
{ 395. Program
void test() class A
{ {
System.out.println("B"); int i;
} }
} class B extends A
public class Manager {
{ int j;
public static void main(String[] args) }
{ class C extends B
A all[] = new A[2]; {
A a1 =new A(); int k;
A a2= new B(); }
all[0]= a1; class Manager
all[1]= a2; {
for(int i = 0; i< all.length; i++) public static void main(String[] args)
{ {
all[i].test(); B b1 = new C();
} A a1 = b1;
} C c1 =(C)a1;
} System.out.println(c1.k);
Output: }
A }
B Output:
394. Program 0
class Manager 396. Program
{ class A
public static void main(String[] args) {
{ int i;
94
Lara Technologies RSTechnologies
} {
class B extends A int i;
{ }
int j; class B extends A
} {
class C extends B int j;
{ }
int k; class C extends B
} {
class Manager int k;
{ }
public static void main(String[] args) class Manager
{ {
B b1 = new C(); public static void main(String[] args)
A a1 = b1; {
B b2 =(B)a1; A a1 = new B();
System.out.println(b2.k); C c1 = (C)a1;
} System.out.println(a1.i);
} System.out.println(c1.i);
Output: System.out.println(c1.j);
Compile time error System.out.println(c1.k);
397. Program B b1 = (B)a1;
class A A a2 = b1;
{ System.out.println(b1.i);
int i; System.out.println(b1.j);
} System.out.println(b1.k);
class B extends A System.out.println(a2.i);
{ System.out.println(a2.j);
int j; }
} }
class C extends B Output:
{ Compile time error
int k; 399. Program
} class A
class Manager {
{ int i;
public static void main(String[] args) }
{ class B extends A
A a1 = new B(); {
A a1 = a; int j;
B b2 =(B)a1; }
System.out.println(b2.j); class C extends B
} {
} int k;
Output: }
Compile time error class Manager
398. Program {
class A public static void main(String[] args)
{
95
Lara Technologies RSTechnologies
A a1 = new B(); {
A a2 = (A)(A)a1; int k;
B b1 = (B)a2; }
C c1 = (C)b1; class Manager
B b2 = (C)a1; {
System.out.println(a1.i); static void test(A a1)
System.out.println(c1.k); {
System.out.println(b2.j); System.out.println(a1.i);
System.out.println(a2.i); System.out.println(a1.j);
System.out.println(a1.k);
} }
} static void test(B b1)
Output: {
Class cast exception System.out.println(b1.i);
400. Program System.out.println(b1.j);
class A System.out.println(b1.k);
{ }
int i; public static void main(String[] args)
} {
class B extends A A a1 = new B();
{ test(a1);
int j; test((B)a1);
} }
class C extends B }
{ Output:
int k; Compile time error
} 402. Program
class Manager class A
{ {
public static void main(String[] args) int i;
{ }
C c1 = (C)new A(); class B extends A
B b2 = (C)new B(); {
C c1 = (B)(C) new A(); int j;
} }
} class C extends B
Output: {
Class cast exception int k;
401. Program }
class A class Manager
{ {
int i; static void test1(A a1)
} {
class B extends A System.out.println(a1.i);
{ }
int j; static void test2(B b1)
} {
class C extends B System.out.println(b1.i);
System.out.println(b1.j);
96
Lara Technologies RSTechnologies
} test(a1);
static void test3(C c1) B b1 = new B();
{ test(b1);
System.out.println(c1.i); C c1 = new C();
System.out.println(c1.j); test(c1);
System.out.println(c1.k); A a11= new A();
} test (a11);
public static void main(String[] args) }
{ }
A a1 = new C(); Output:
test1(a1); Class cast exception
test2((B)a1); 404. Program
test3((C)a1); class A
test1((B)a1); {
test2((C)a1); int i;
test3((C)a1); }
test1((B)(A)(C)a1); class B extends A
test2((B)(C)a1); {
test3((B)(C)(A)a1); int j;
} }
} class C extends B
Output: {
Compile time error int k;
403. Program }
class A
{ class Manager
int i; {
} static void test1(A a1)
class B extends A {
{ System.out.println("A");
int j; }
} static void test1(B b1)
class C extends B {
{ System.out.println("B");
int k; }
} static void test1(C c1)
{
class Manager System.out.println("C");
{ }
static void test(A a1) public static void main(String[] args)
{ {
B b1 =(B)a1; A a1 = new C();
C c1 = (C)a1; test1(a1);
System.out.println(b1.j); test1((B)a1);
System.out.println(c1.k); test1((C)a1);
} test1((B)(A)(C)(A)(B)a1);
public static void main(String[] args) }
{ }
A a1 = new A(); Output:
97
Lara Technologies RSTechnologies
A
B class Manager
C {
B static void test1(B b1)
405. Program {
class A System.out.println("B");
{ }
int i; public static void main(String[] args)
} {
class B extends A A a1 = new C();
{ test1((B)a1);
int j; test1((C)a1);
} test1((B)(A)(C)(A)(B)a1);
class C extends B }
{ }
int k; Output:
} B
B
class Manager B
{ 407. Program
static void test1(B b1) class A
{ {
System.out.println("B"); int i;
} }
public static void main(String[] args) class B extends A
{ {
A a1 = new C(); int j;
test1(a1); }
test1((B)a1); class C extends B
test1((C)a1); {
test1((B)(A)(C)(A)(B)a1); int k;
} }
} class Test
Output: {
Compile Time Error void test (double d)
406. Program {
class A System.out.println("double");
{ }
int i; void test (Object obj)
} {
class B extends A System.out.println("object");
{ }
int j; }
} class Manager
class C extends B {
{ public static void main(String[] args)
int k; {
} Test t = new Test();
t.test(10);
98
Lara Technologies RSTechnologies
t.test(10.0); {
t.test(new A()); int i;
t.test(new B()); }
t.test(new C()); class B extends A
t.test(new Object()); {
t.test((B)new C()); int j;
} }
} class C extends B
Output: {
double int k;
double }
object class Manager
object {
object public static void main(String[] args)
object {
object A a1 = new B();
408. Program C c1 = (C)a1;
System.out.println(a1.i);
class A System.out.println(c1.j);
{ System.out.println(c1.j);
int i; System.out.println(c1.k);
} B b1 = (B)a1;
class B extends A System.out.println(b1.i);
{ System.out.println(b1.j);
int j; System.out.println(b1.k);
} System.out.println(a3.i);
class C extends B System.out.println(a3.j);
{ }
int k; }
} Output:
Compile time error
class Manager 410. Program
{ class A
public static void main(String[] args) {
{ int i;
A a1 = new C(); }
B b1 = (B)a1; class B extends A
C c1 = (C)b1; {
C c2 = (C)a1; int j;
C c3 = (C)(B)a1; }
C c4 =(C)(B)(A)(B)(C)b1; class C extends B
System.out.println(b1.j); {
} int k;
} }
Output:
0 class Manager
409. Program {
class A public static void main(String[] args)
{
99
Lara Technologies RSTechnologies
A a1 = new A(); class B extends A
B b1 = (B)a1; {
C c1 = (C)a1; int j;
System.out.println(b1.i); }
System.out.println(b1.j); class C extends B
System.out.println(b1.j); {
System.out.println(a1.i); int k;
System.out.println(a1.j); }
}
} class Manager
Output: {
Compile time error public static void main(String[] args)
411. Program {
class A C c1 = (C)new A();
{ B b1 = (C)new B();
int i; C c1 = (B)(C)new A();
} }
class B extends A }
{ Output:
int j; Compile time error
} 413. Program
class C extends B class A
{ {
int k; int i;
} }
class Manager class B extends A
{ {
public static void main(String[] args) int j;
{ }
A a1 = new A(); class C extends B
A a2 = a1; {
B b1 = (B)a2; int k;
C c1 = (C)a1; }
B b2 = (C)a1; class Manager
System.out.println(a1.i); {
System.out.println(c1.k); public static void main(String[] args)
System.out.println(b2.j); {
System.out.println(a2.i); C c1 = (C)new A();
System.out.println(a2.i); B b1 = (C)new B();
}
} }
Output: }
Class cast exception Output:
412. Program Class cast exception
class A 414. Program
{ class A
int i; {
} int i;
100
Lara Technologies RSTechnologies
} static void test1(A a1)
class B extends A {
{ System.out.println(a1.i);
int j; }
} static void test2(B b1)
class C extends B {
{ System.out.println(b1.i);
int k; System.out.println(b1.j);
} }
class Manager static void test3(C c1)
{ {
static void test(A a1) System.out.println(c1.i);
{ System.out.println(c1.j);
System.out.println(a1.i); System.out.println(c1.k);
System.out.println(a1.j); }
System.out.println(a1.k); public static void main(String[] args)
} {
static void test(B b1) A a1 = new C();
{ test1(a1);
System.out.println(b1.i); test2((B)a1);
System.out.println(b1.j); test3((C)a1);
System.out.println(b1.k); test1((B)a1);
} test2((C)a1);
public static void main(String[] args) test3((B)a1);
{ test1((B)(A)(C)a1);
A a1 = new B(); test2((B)(C)a1);
test(a1); test3((B)(C)(A)a1);
test((B)a1);
} }
}
} Output:
Output: Compile time error
Compile time error 416. Program
415. Program class A
class A {
{ int i;
int i; }
} class B extends A
class B extends A {
{ int j;
int j; }
} class C extends B
class C extends B {
{ int k;
int k; }
}
class Manager
class Manager {
{ static void test1(A a1)
101
Lara Technologies RSTechnologies
{
B b1 =(B)a1; }
C c1=(C)a1; if(o1 instanceof C)
System.out.println("b1.j"); {
System.out.println("c1.k"); System.out.println("able to
} convert to C");
public static void main(String[] args) }
{ }
A a1 = new C(); }
test1(a1); class Manager
B b1 = new B(); {
test1(b1); public static void main(String[] args)
C c1 = new C(); {
test1(c1); A a1 = new A();
A a11 = new A(); A a2 = new B();
test1(a1); A a3 = new C();
} B b1 = new B();
} B b2 = new C();
Output: Util.test(a1);
b1.j System.out.println("------");
c1.k Util.test(a2);
class cast exception System.out.println("------");
417. Program Util.test(a3);
class A System.out.println("------");
{ Util.test(b1);
} System.out.println("------");
class B extends A Util.test(b2);
{ System.out.println("------");
} Util.test(new D());
class C extends B }
{ }
} Output:
class D extends C can be converted to A
{ ------
} can be converted to A
class Util able to convert to B
{ ------
static void test(Object o1) can be converted to A
{ able to convert to B
if (o1 instanceof A) able to convert to C
{ ------
System.out.println("can be can be converted to A
converted to A"); able to convert to B
} ------
can be converted to A
if (o1 instanceof B) able to convert to B
{ able to convert to C
System.out.println("able to ------
convert to B"); can be converted to A
102
Lara Technologies RSTechnologies
able to convert to B System.out.println("------");
able to convert to C Util.test(a2);
418. Program System.out.println("------");
class A Util.test(a3);
{ System.out.println("------");
} Util.test(b1);
class B extends A System.out.println("------");
{ Util.test(b2);
} System.out.println("------");
class C extends B Util.test(new D());
{ }
} }
class D extends C Output:
{ Compile time error
} 419. Program
class Util class A
{ {
void test(Object o1) }
{ class B extends A
if (o1 instanceof A) {
{ }
System.out.println("can be class C extends B
converted to A"); {
} }
class Manager extends C
if (o1 instanceof B) {
{ public static void main(String[] args)
System.out.println("able to {
convert to B"); Object all[] = new Object[1];
Object o1 = new Object();
} A a1 = new A();
if(o1 instanceof C) B b1 = new B();
{ C c1 = new C();
System.out.println("able to Manager m1 = new Manager();
convert all[0]=m1;
to C"); all[1]=c1;
} all[2]=b1;
} all[3]=a1;
} all[4]=o1;
class Manager Object obj = null;
{ for(int i=0;i<all.length;i++)
public static void main(String[] args) {
{ obj = all[i];
A a1 = new A(); if(obj instanceof Object)
A a2 = new B(); {
A a3 = new C(); System.out.println("Object type");
B b1 = new B();
B b2 = new C(); }
Util.test(a1); if(obj instanceof A)
103
Lara Technologies RSTechnologies
{ Object obj = null;
System.out.println("A type"); for(int i=0;i<all.length;i++)
{
} obj = all[i];
if(obj instanceof B) if(obj instanceof Object)
{ {
System.out.println("B type"); System.out.println("Object type");
} }
if(obj instanceof C) if(obj instanceof A)
{ {
System.out.println("C type"); System.out.println("A type");
} }
if(obj instanceof Manager) if(obj instanceof B)
{ {
System.out.println("Manager type"); System.out.println("B type");
System.out.println("------");
} }
} if(obj instanceof C)
} {
} System.out.println("C type");
Output: }
RTE if(obj instanceof Manager)
420. Program {
class A System.out.println("Manager type");
{
} }
class B extends A
{ }
}
class C extends B }
{
} }
class Manager extends C Output:
{ Object type
public static void main(String[] args) A type
{ B type
Object all[] = new Object[5]; C type
Object o1 = new Object(); Manager type
A a1 = new A(); Object type
B b1 = new B(); A type
C c1 = new C(); B type
Manager m1 = new Manager(); C type
all[0]=m1; Object type
all[1]=c1; A type
all[2]=b1; B type
all[3]=a1; Object type
all[4]=o1; A type
104
Lara Technologies RSTechnologies
Object type Systematization("B");
421. Program }
class A }
{ class C extends B
int i; {
} void test()
class B extends A {
Systematization("C");
{ }
int j; }
} class Utils
class C extends B {
{ static void method(A a)
int k; {
} a.test();
class Manager }
{ }
public static void main(String[] args) public class Manager
{ {
A a1 = new A(); public static void main(String[] args)
A a2 = new B(); {
C c1 = new C(); A a1=new A();
A a=new C(); B b1=new B();
A a3=new B(); C c1=new C();
B b1 = (B)a3; Utils u=new Utils();
System.out.println(a1.i); u.method(a1);
System.out.println(c1.k); u.method(b1);
System.out.println(a2.i); u.method(c1);
System.out.println(a2.i); }
} }
} Output:
Output: A
0 B
0 C
0 423. Program
0 package com.prasu;
422. Program import bsh.util.Util;
class A class A
{ {
void test() int i=10;
{ }
Systematization("A"); class B extends A
} {
} int j=20;
class B extends A }
{
void test() public class Manager
{ {
public static void main(String[] args)
105
Lara Technologies RSTechnologies
{ normal type
A a1=new A(); 425. Program
System.out.println(a1.i); class A
System.out.println(a1.j); {
B b1=new B(); int i=10;
System.out.println(b1.i); }
System.out.println(b1.j); class B extends A
} {
} int j=20;
Output: }
compile time error class Utils
424. Program {
abstract class Person void test(A a1)
{ {
abstract void walkingstyle(); System.out.println(a1.i);
} System.out.println(a1.j);
class Male extends Person }
{ }
void walkingstyle() public class Manager
{ {
System.out.println("special type"); public static void main(String[] args)
} {
} A a1=new A();
class Female extends Person B b1=new B();
{ Utils u=new Utils();
void walkingstyle() u.test(a1);
{ u.test(b1);
System.out.println("normal type"); }
} }
} Output:
class Utils Compile Time Error
{
static void checkwalkingstyle(Person p)
{
p.walkingstyle();
}
}
public class Manager
{
public static void main(String[] args)
{
Male m1=new Male();
Female f1=new Female();
Utils.checkwalkingstyle(m1);
Utils.checkwalkingstyle(f1);
}
}
Output:
special type
106
Lara Technologies RSTechnologies
107