Quizzes
Site Language: English
Українська
English
Русский
Programming Tests
Login
Sign Up
Programming Tests
Theory
Snippets
Papers
Landing
Android
Prices
FAQ
Cosmo Story
Terms and Conditions
Privacy Policy
Cookies Policy
Send Feedback
inheritance
:
Content language: English
Русский
What will be printed out as a result of the following code execution / compilation? class A { public A() { System.out.print("A"); } } class B { public B() { System.out.print("B"); } } class C { public C() { System.out.print("C"); } } public class D extends C { private A objA = new A(); private static B objB = new B(); public D() { System.out.print("D"); } public static void main(String[] args){ new D(); } }
inheritance
What happens after the following code is compiled and run: 01: interface TheInterface { 02: void print(); 03: } 04: 05: class TheClass implements TheInterface { 06: public void print() { 07: System.out.println("TheClass"); 08: } 09: } 10: 11: public class ClassConversion { 12: public static void main(String[] args) { 13: TheClass c = new TheClass(); 14: TheInterface i = c; 15: i.print(); 16: } 17: }
inheritance
What will be the result of the compilation and execution of the following code? 01. class A { 02. public void process() { System.out.print("A,"); } 03. } 04. public class B extends A { 05. public void process() throws IOException { 06. super.process(); 07. System.out.print("B,"); 08. throw new IOException(); 09. } 10. 11. public static void main(String[] args) { 12. try { new B().process(); } 13. catch (IOException e) { System.out.println("Exception"); } 14. } 15. }
inheritance
What is the result of the following code compilation? class A { public void m(Number n) { n = 5 / 3; System.out.println("class A, method m : " + n); } } class B extends A { public void m(Double d) { d = d / 3; System.out.println("class B, method m : " + d); } } public class MainClass { public static void main(String args[]) { A a = new B(); a.m(5.0); } }
inheritance
What will be printed to console as a result of the following code execution? public class Test { public static void main(String[] s) { A a = new B(); a.b(); } } class A { void a() { System.out.println("A-a"); } void b() { System.out.println("A-b"); a(); } } class B extends A { void a() { System.out.println("B-a"); } void b() { System.out.println("B-b"); super.b(); } }
inheritance
What will be the following program's output? package tutorial.base; public class TypesTutorial { public static void main(String... args) { A alpha = new B(); } } class A { A() { System.out.print("A"); a(); } void a() { System.out.print("a"); } } class B extends A { B() { System.out.print("B"); a(); } void a() { System.out.print("b"); } }
inheritance
What is the result of the following code compilation and execution? public class Test extends A { public int i = 1; public static void main(String... args) { System.out.print(new Test().i); System.out.print(new A().i); System.out.print( ((A)new Test()).i ); } } class A { public int i = 2; }
inheritance
Is it possible to inherit from the class java.lang.String?
inheritance
What is the result of the following code compilation and execution? public class MainClass { public static void test(int ...a) { System.out.println("int..."); } public static void test(Integer ...a) { System.out.println("Integer..."); } public static void test(Number ...a) { System.out.println("Number..."); } public static void main(String args[]){ Number n = new Integer(1); test(n.intValue()); } }
inheritance
What will be printed? class ClassA { int x = 1; public void printX() { System.out.println(getX()); } public int getX() { return x; } } class ClassB extends ClassA { int x = 2; public int getX() { return x + 1; } } public class Test { public static void main(String[] args) { ClassA a = new ClassB(); System.out.println(a.x); } }
inheritance
← Prev
1
2
3
4
5
Next →
Sign Up Now
or
Subscribe for future quizzes