Tag Archives: public

Given: class Base { public static void main(String[] args) { System.out.println("Base " + args[2]); }

Given: class Base {public static void main(String[] args) {System.out.println(“Base ” + args[2]);}}public class Sub extends Base{public static void main(String[] args) {System.out.println(“Overriden ” + args[1]);}}And the commands:javac Sub.javajava Sub 10 20 30What is the result? A. Overridden 20 B. Base 30 Overridden 20 C. Base 30 D. Overridden 20 Base 30 Correct Answer: A

The protected modifier on a Field declaration within a public class means that the field ______________.

The protected modifier on a Field declaration within a public class means that the field ______________. A. Can be read and written from this class and its subclasses defined in any package B. Can be read but not written from outside the class C. Can be read and written from this class and its subclasses only within the… Read More »

Given the code fragment: interface SampleClosable { public void close () throws java.io.IOException;

Given the code fragment:interface SampleClosable {public void close () throws java.io.IOException;}Which three implementations are valid? A. Option A B. Option B C. Option C D. Option D E. Option E Correct Answer: A,C,E A: Throwing the same exception is fine.C: Using a subclass of java.io.IOException (here java.io.FileNotFoundException) is fineE: Not using a throw clause is fine.

Given: public class App { // Insert code here System.out.print("Welcome to the world of Java"); } } Which

Given:public class App {// Insert code hereSystem.out.print(“Welcome to the world of Java”);}}Which two code fragments, when inserted independently at line // Insert code here, enable the program to execute and print the welcome message on the screen? A. static public void main (String [] args) { B. static void main (String [] args) { C. public static void… Read More »

Given the code fragment: public void foo(Function<Integer, String> fun) {…} Which two compile?

Given the code fragment:public void foo(Function<Integer, String> fun) {…}Which two compile? (Choose two.) A. foo( n -> Integer.toHexString(n) ) B. foo( toHexString ) C. foo( n -> n + 1 ) D. foo( int n -> Integer.toHexString(n) ) E. foo( n -> Integer::toHexString ) F. foo( Integer::toHexString ) G. foo( n::toHexString ) H. foo( (int n) -> Integer.toHexString(n)… Read More »

Given: /code/a/Test.java containing: (Exhibit) and /code/b/Best.java containing: package b; public class

Given:/code/a/Test.javacontaining:and/code/b/Best.javacontaining:package b;public class Best { }Which is the valid way to generate bytecode for all classes? A. javac -d /code /code/a/Test.java /code/b/Best.java B. java /code/a/Test.java C. javac -d /code /code/a/Test.java D. javac -d /code /code/a/Test E. java /code/a/Test.java /code/b/Best.java F. java -cp /code a.Test Correct Answer: A

Given: public class FieldInit { char c; boolean b; float f; void printAll() { System.out.println("c =

Given:public class FieldInit {char c;boolean b;float f;void printAll() {System.out.println(“c = ” + c);System.out.println(“c = ” + b);System.out.println(“c = ” + f);}public static void main(String[] args) {FieldInit f = new FieldInit();f.printAll();}}What is the result? A. c = null b = false f = 0.0F B. c = 0 b = false f = 0.0f C. c = b =… Read More »

Given: public class SampleClass { public static void main(String[] args) { AnotherSampleClass asc = new

Given:public class SampleClass {public static void main(String[] args) {AnotherSampleClass asc = new AnotherSampleClass(); SampleClass sc = newSampleClass();sc = asc;System.out.println(“sc: ” + sc.getClass());System.out.println(“asc: ” + asc.getClass());}}class AnotherSampleClass extends SampleClass {}What is the result? A. sc: class AnotherSampleClass asc: class SampleClass B. sc: class SampleClass asc: class AnotherSampleClass C. sc: class AnotherSampleClass asc: class AnotherSampleClass D. sc: class Object asc:… Read More »

Given: class Test int a1; public static void doProduct(int a) { a = a * a; ) public static void doString(StringBuilder

Given:class Testint a1;public static void doProduct(int a) {a = a * a;)public static void doString(StringBuilder s) {s.append(” ” + s);}public static void main(String[] args) {Test item = new Test();item.a1 = 11;StringBuilder sb = new StringBuilder(“Hello”);Integer i = 10;doProduct(i);doString(sb);doProduct(item.a1);System.out.println(i + ” ” + sb + ” ” + item.a1);}}What is the result? A. 100 Hello 121 B. 100 Hello… Read More »

Given: /code/a/Test.java containing: (Exhibit) and /code/b/Best.java containing: package b; public class

Given:/code/a/Test.javacontaining:and/code/b/Best.javacontaining:package b;public class Best { }Which is the valid way to generate bytecode for all classes? A. java /code/a/Test.java /code/b/Best.java B. java -cp /code a.Test C. javac -d /code /code/a/Test.java D. javac -d /code /code/a/Test.java /code/b/Best.java E. javac -d /code /code/a/Test F. java /code/a/Test.java Correct Answer: D