Tag Archives: class

Given: class Overloading { int x(double d) { System.out.println("one"); return 0; } String x(double d)

Given:class Overloading {int x(double d) {System.out.println(“one”);return 0;}String x(double d) {System.out.println(“two”);return null;}double x(double d) {System.out.println(“three”);return 0.0;}public static void main(String[] args) {new Overloading().x(4.0);}}What is the result? A. Three B. One C. Two D. Compilation fails. Correct Answer: D

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: (Exhibit) What must be added in line 1 to compile this class?

Given:What must be added in line 1 to compile this class? A. catch(FileNotFoundException | IOException e) { } B. catch(IndexOutOfBoundsException e) { }catch(FileNotFoundException e) { } C. catch(FileNotFoundException e) { }catch(IndexOutOfBoundsException e) { } D. catch(IOException e) { } E. catch(FileNotFoundException | IndexOutOfBoundsException e) { } Correct Answer: D

Given this class: (Exhibit) Which two changes would encapsulate this class and ensure that the area field

Given this class:Which two changes would encapsulate this class and ensure that the area field is always equal to length * heightwhenever the Rectangle class is used? A. Call the setArea method at the beginning of the setLength method. B. Call the setArea method at the end of the setHeight method. C. Change the setArea method to private.… Read More »