Tag Archives: class

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 the following class: (Exhibit) Which two changes would encapsulate this class and ensure that the

Given the following 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 setHeight method. B. Change the area field to public. C. Call the setArea method at the end of the setHeight method.… Read More »

Given: (Exhibit) Which two changes need to be made to make this class compile? (Choose two.)

Given:Which two changes need to be made to make this class compile? (Choose two.) A. Change Line 1 to an abstract class:public abstract class API { B. Change Line 2 to an abstract method:public abstract void checkValue(Object value)throws IllegalArgumentException; C. Change Line 2 access modifier to protected:protected void checkValue(Object value)throws IllegalArgumentException; D. Change Line 1 to a class:public… 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 the following two classes: (Exhibit) How should you write methods in the ElectricAccount class

Given the following two classes:How should you write methods in the ElectricAccount class at line n1 so that the member variable bill is always equal to the value of the member variable kwh multiplied by the member variable rate?Any amount of electricity used by a customer (represented by an instance of the customer class) must contribute to the… Read More »