Java-Questions

.docx

School

Stevens Institute Of Technology *

*We aren’t endorsed by this school

Course

556

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

25

Uploaded by ProfSnowWombat32

Report
1) Tinku has written the code like below. But it is showing compile time error. Can you identify what mistake he has done? 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 class X { //Class X Members } class Y { //Class Y Members } class Z extends X, Y { //Class Z Members } View Answer 2) What will be the output of this program? 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 class A { int i = 10 ; } class B extends A { int i = 20 ; } public class MainClass { public static void main(String[] args) { A a = new B(); System.out.println(a.i); } }
1 9 View Answer 3) What will be the output of the below program? 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 class A { { System.out.println( 1 ); } } class B extends A { { System.out.println( 2 ); } } class C extends B { { System.out.println( 3 ); } } public class MainClass { public static void main(String[] args) { C c = new C(); } }
2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 View Answer 4) Can a class extend itself? View Answer 5) What will be the output of the following program? 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 class A { String s = "Class A" ; } class B extends A { String s = "Class B" ; { System.out.println( super .s); } } class C extends B { String s = "Class C" ; { System.out.println( super .s); } } public class MainClass { public static void main(String[] args) { C c = new C();
9 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 0 3 1 3 2 System.out.println(c.s); } } View Answer 6) What will be the output of this program? 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 class A { static { System.out.println( "THIRD" ); } } class B extends A { static { System.out.println( "SECOND" ); } } class C extends B { static { System.out.println( "FIRST" ); }
6 1 7 1 8 1 9 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 0 3 1 } public class MainClass { public static void main(String[] args) { C c = new C(); } } View Answer 7) What will be the output of the below program? 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 class A { public A() { System.out.println( "Class A Constructor" ); } } class B extends A { public B() { System.out.println( "Class B Constructor" ); } } class C extends B {
4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 0 3 1 public C() { System.out.println( "Class C Constructor" ); } } public class MainClass { public static void main(String[] args) { C c = new C(); } } View Answer 8) Private members of a class are inherited to sub class. True or false? View Answer 9) What will be the output of the following program? 1 2 3 4 5 6 7 8 9 1 0 class X { static void staticMethod() { System.out.println( "Class X" ); } } class Y extends X { static void staticMethod()
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help