Question : Which two modifications, made independently, enable the code to compile?
A. Make the method at line n1 public. B. Make the method at line n2 public. C. Make the method at line n3 public. D. Make the method at line n3 protected. E. Make the method at line n4 public.
1. A,B
2. B,C
3. C,D
4. D,E
Correct Answer : 3 Explanation:
Question : What is the name of the Java concept that uses access modifiers to protect variables and hide them within a class?
Correct Answer : 1 Explanation: Using the private modifier is the main way that an object encapsulates itself and hide data from the outside world.
Question : Given the code fragment:
public static void main(String[] args){ short s1 = 200; Integer s2 = 400; Long s3 = (long) s1+s2; //line n1 String s4 = (String)(s3*s2); //line n2 System.out.println("Sum is " + s4);
}
What is the result?
1. Sum is 600 2. Compilation fails at line n1. 3. Compilation fails at line n2. 4. A ClassCastException is thrown at line n1. 5. A ClassCastException is thrown at line n2.
2. public abstract class Toy{ public int caicuiatePrice (Toy t) ; void printToy (Toy t); } 3. Access Mostly Uused Products by 50000+ Subscribers public abstract class Toy{ public int caicuiatePrice (Toy t) ; public final void printToy (Toy t) {/*code goes here*/} }
4. public abstract class Toy{ public abstract int caicuiatePrice(Toy t){/*Code goes here*/} ; void printToy (Toy t){/*Code goes here*/}; }