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
polymorphism
:
Content language: English
Русский
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: }
polymorphism
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); } }
polymorphism
Given the following code public class OverrideThrowsTest { public static void main(String[] args) // 1 { A a = new A(); a.method(); A ab = new B(); ab.method(); B b = new B(); b.method(); } } class A { public void method() throws IOException {} } class B extends A { public void method() throws FileNotFoundException {} } Select all the answers, for which, if placed into line 1, code will compile.
polymorphism
What will be the result of the following code compilation and execution? public class Base { public Object print() { return "Object from base method"; } public static void main(String[] args) { Base test = new Child(); System.out.println(test.print()); } } class Child extends Base { public String print() { return "String from child method"; } }
polymorphism
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(); } }
polymorphism
Should all the elements in Java arrays be of the same type?
polymorphism
What will be the result of the program execution? public class Tenor extends Singer { public static String sing() { return "fa"; } public static void main(String[] args) { Tenor t = new Tenor(); Singer s = new Tenor(); System.out.println(t.sing() + " " + s.sing()); } } class Singer { public static String sing() { return "la"; } }
polymorphism
What will be the result of compiling and running the following code? public class Test { public static void main(String... args) { test("A", "B"); } public static void test(String... str) { System.out.print("A"); } public static void test(String str1, String str2) { System.out.print("B"); } public static void test(String str1, String... str2) { System.out.print("C"); } }
polymorphism
What will be printed by the following code? public class Main { public static void var(Integer x, int y) { System.out.println("Integer int"); } public static void var(Object... x) { System.out.println("Object"); } public static void var(int... x) { System.out.println("int... x"); } public static void var(Integer... x) { System.out.println("Integer..."); } public static void main(String... args) { int i = 0; Integer i2 = 127; var(i, i2); } }
polymorphism
There are two classes: package pak1; import pak2.B; public class A { void doAThings() { System.out.print("A "); } public static void main(String[] args) { A a = new B(); a.doAThings(); } } and package pak2; import pak1.A; public class B extends A { public void doAThings() { System.out.println("I'm B ;)"); } } What will happen when you try to compile both classes and run the main-method?
polymorphism
← Prev
1
2
Next →
Sign Up Now
or
Subscribe for future quizzes