Programming Concepts using Java, Quiz 1
Consider the Java code given below.
interface Readable{ public default void read(){ System.out.println("Reads"); }}interface Writable{ public default void write(){ System.out.println("Writes"); }}class Document implements Readable, Writable{ public void read(){ System.out.println("Reads the lines in doc"); }}public class Test { public static void main(String[] args) { Readable r1 = new Document(); r1.read(); r1.write(); }
}Choose the correct option
Consider the Java code given below. interface Readable{ public default void read(){ System.out.println("Reads"); } } interface Writable{ public default void write(){ System.out.println("Writes"); } } class Document implements Readable, Writable{ public void read(){ System.out.println("Reads the lines in doc"); } } public class Test { public static void main(String[] args) { Readable r1 = new Document(); r1.read(); r1.write(); } } Choose the correct option Consider the Java code given below. interface Iterator{ public boolean has_next(); public Object get_next(); } class Faculty{ // ... private class FacIter implements Iterator{ // .... public boolean has_next() { // ... return false; } public Object get_next() { // ... } } public Iterator getIterator() { return new FacIter(); } } public class Test{ public static void main(String[] args) { Faculty fList = new Faculty(); //CODE BLOCK // LINE-1 boolean hasNext = iter.has_next(); // LINE-2 } } Identify the appropriate statements to fill in place of LINE-1 in order to correctly invoke method has_next() as given in LINE-2. Consider the Java code given below. class Experiment{ public void begin(){ Simulation s = new Simulation(this); // LINE 1 s.simulate(); System.out.println("Experiment finished"); } public void alarm(){ System.out.println("Collected results"); } } class Simulation{ Experiment exp; public Simulation(Experiment e){ exp = e; } public void simulate(){ System.out.println("Simulated Successfully"); exp.alarm(); // LINE 2 } } public class Test { public static void main(String[] args) { Experiment e1 = new Experiment(); e1.begin(); } } Choose the correct option.