Java Programming :: Declarations and Access Control
-
which two code fragments inserted at end of the program, will allow to compile?interface DoMath { double getArea(int rad); } interface MathPlus { double getVol(int b, int h); } /* Missing Statements ? */
- class AllMath extends DoMath { double getArea(int r); }
- interface AllMath implements MathPlus { double getVol(int x, int y); }
- interface AllMath extends DoMath { float getAvg(int h, int l); }
- class AllMath implements MathPlus { double getArea(int rad); }
- abstract class AllMath implements DoMath, MathPlus { public double getArea(int rad) { return rad * rad * 3.14; } }
-
Which two statements are true for any concrete class implementing the java.lang.Runnable interface?
- You can extend the Runnable interface as long as you override the public run() method.
- The class must contain a method called run() from which all code for that thread will be initiated.
- The class must contain an empty public void method named run().
- The class must contain a public void method named runnable().
- The class definition must include the words implements Threads and contain a method called run().
- The mandatory method must be public, with a return type of void, must be called run(), and cannot take any arguments.
-
which two statements, added independently at beginning of the program, allow the code to compile?/* Missing statements ? */ public class NewTreeSet extends java.util.TreeSet { public static void main(String [] args) { java.util.TreeSet t = new java.util.TreeSet(); t.clear(); } public void clear() { TreeMap m = new TreeMap(); m.clear(); } }
- No statement is required
- import java.util.*;
- import.java.util.Tree*;
- import java.util.TreeSet;
- import java.util.TreeMap;
-
which statement is true?package testpkg.p1; public class ParentUtil { public int x = 420; protected int doStuff() { return x; } } package testpkg.p2; import testpkg.p1.ParentUtil; public class ChildUtil extends ParentUtil { public static void main(String [] args) { new ChildUtil().callStuff(); } void callStuff() { System.out.print("this " + this.doStuff() ); /* Line 18 */ ParentUtil p = new ParentUtil(); System.out.print(" parent " + p.doStuff() ); /* Line 20 */ } }