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 the output of the following code? interface I_A { public void out1(); } interface I_B { public void out2(); } class Impl implements I_A, I_B { // 1 public void out2() { System.out.print("2"); } public void out1() { System.out.print("1"); } } public class Test { public static void main(String[] args) { Impl impl = new Impl(); I_A a; a = impl; a.out1(); ((I_B) a).out2(); // 2 } }
inheritance
What will happen if you try to compile and run this program? class Box { int b,w; void Box(int b, int w) { this.b = b; this.w = w; } } public class MyBox extends Box { MyBox() { super(10, 15); System.out.println(b + "," + w); } static public void main(String args[]) { MyBox box = new MyBox(); } }
inheritance
What happens as a result of the following code execution? public class Test { class A { private void act(){}; } class B extends A { protected void act(){}; } class C extends B { public void act(){}; } class D extends B { void act(){}; } public static void main(String[] args){ A obj = new Test().new D(); obj.act(); } }
inheritance
What will be the output of the following code? class Super { static String ID = "QBANK"; } class Sub extends Super{ static { System.out.print("In Sub"); } } class Test{ public static void main(String[] args) { System.out.println(Sub.ID); } }
inheritance
What will be printed after compiling and running the following code? public class Test { public static void main(String[] args) { Sub sub = new Sub(); System.out.println(sub.getWidth()); } } class Sub extends Base { private Dimension size; public Sub() { this.size = new Dimension(50, 50); } public Dimension getSize() { return size; } } class Base { private int width; private int height; private Dimension size = new Dimension(20, 20); Base() { this.width = getSize().width; this.height = getSize().height; } Dimension getSize() { return size; } int getWidth() { return width; } int getHeight() { return height; } }
inheritance
Given the following two classes: public class Parent { protected int i; public Parent() { i = 1; } } public class Child extends Parent { private int i; public Child() { this.i = ((Child)new Parent()).getI(); this.i = this.i++ + ++super.i; } public int getI() { return i; } } What will be the output of the following code? public class Test { public static void main(String[] args) { Child c = new Child(); System.out.println(c.getI()); } }
inheritance
What will be the result of compiling and running the following code: import java.io.*; public class NewClass { public static void main(String[] args) throws Exception { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); ObjectOutputStream oOut = new ObjectOutputStream(bOut); oOut.writeObject(new Sub()); System.out.println(""); ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray()); ObjectInputStream oIn = new ObjectInputStream(bIn); oIn.readObject(); } } class Base { private int baseField = getInt(1); public Base() { System.out.print("Base.Base() "); } protected int getInt(int i) { System.out.print(i + " "); return i; } } class Sub extends Base implements Serializable { private int subField = getInt(2); public Sub() { System.out.print("Sub.Sub() "); } }
inheritance
What will be the result of compilation and execution of the following code? public class Test { public static void main(String[] args) throws CloneNotSupportedException { A a1 = new A(); A a2 = (A) a1.clone(); System.out.println(a1 == a2); System.out.println(a1.min == a2.min); System.out.println(a1.max == a2.max); } } class A implements Cloneable { Integer min = new Integer(100); Integer max = new Integer(1000); @Override protected Object clone() throws CloneNotSupportedException { return super.clone(); } }
inheritance
What will be the result of execution of the following code? public class Parent { protected String value = "parent"; public static void main(String[] args) { Parent parent = new Child(); Child child = new Child(); System.out.println(parent.value); System.out.println(child.value); } } class Child extends Parent { protected String value = "child"; }
inheritance
What will happen while running the following code? public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); try { t.start(); } catch (IOException ioe) { System.out.println("IOException"); } } public void run() throws IOException { File f = new File("file.txt"); FileWriter fw = new FileWriter(f); } }
inheritance
← Prev
1
2
3
4
5
Next →
Sign Up Now
or
Subscribe for future quizzes