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
Русский
Given the following code, which of the numbered lines should be commented, to have the code compile and run successfully? Select the appropriate line numbers. class Parent { } class Child extends Parent { } class Child2 extends Parent { } public class ArrayTest { public static void main(String[] args) { Parent[] arr1 = new Child[3]; arr1[0] = new Parent(); //1 arr1[1] = new Child(); //2 arr1[2] = new Child2(); //3 arr1[3] = new Child(); //4 Child2[] arr2 = {new Child2(), new Child2(), new Child2()}; add(arr2); } public static void add(Parent[] arr) { arr[0] = new Parent(); //5 arr[1] = new Child(); //6 arr[2] = new Child2(); //7 arr[3] = new Child2(); //8 } }
polymorphism
How much money in the Jack pocket ? public class Main { public static void main(String[] args) { RichJack jack = new RichJack(); jack.showYourWallet(); } } class Jack { Jack() { this.sayHello(); } public void sayHello() { System.out.println("I'm Jack!"); } } class RichJack extends Jack { private int money = 0; public RichJack() { money += 100; }; public void sayHello() { money += 1000000000; // one billion System.out.println("I'm rich Jack!"); } public void showYourWallet() { System.out.println("I have quite some money, about $" + money); }; }
polymorphism
What is the output of the following program? public class Greek { int i = 1; public int getI() { System.out.print("Super"); return i; } public static void main(String arhs[]) { Greek ga = new Arabik(); System.out.print(ga.i + " " + ga.getI()); } } class Arabik extends Greek { int i = 2; public int getI() { System.out.print("Sub"); return i; } }
polymorphism
← Prev
1
2
Next →
Sign Up Now
or
Subscribe for future quizzes