Tag Archives: void

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

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 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 »

1.class StaticMethods { 2.static void one() { 3.two(); 4.StaticMethods.two(); 5.three(); 6.StaticMethods.four();

1.class StaticMethods {2.static void one() {3.two();4.StaticMethods.two();5.three();6.StaticMethods.four();7.}8.static void two() { }9.void three() {10.one();11.StaticMethods.two();12.four();13.StaticMethods.four();14.}15.void four() { }16.}Which three lines are illegal? A. line 10 B. line 11 C. line 3 D. line 13 E. line 4 F. line 12 G. line 5 H. line 6 Correct Answer: D,G,H

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: public class TestLoop { public static void main(String[] args) { int array[] = {0, 1, 2, 3, 4};

Given:public class TestLoop {public static void main(String[] args) {int array[] = {0, 1, 2, 3, 4};int key = 3;for (int pos = 0; pos < array.length; ++pos) {if (array[pos] == key) {break;}}System.out.print(“Found ” + key + “at ” + pos);}}What is the result? A. Found 3 at 2 B. Found 3 at 3 C. Compilation fails D. An… Read More »