Which of the following are true about the following code? (Choose all that apply)public class Create { Create() { System.out.print("1 "); } Create(int num) { System.out.print("2 "); } Create(Integer num) { System.out.print("3 "); } Create(Object num) { System.out.print("4 "); } Create(int... nums) { System.out.print("5 "); } public static void main(String[] args) { new Create(100); new Create(1000L); }}*A. The code prints out 2 4.B. The code prints out 3 4.C. The code prints out 4 2.D. The code prints out 4 4.E. The code prints 3 4 if you remove the constructor Create(int num).F. The code prints 4 4 if you remove the constructor Create(int num).G. The code prints 5 4 if you remove the constructor Create(int num).
Question
Which of the following are true about the following code? (Choose all that apply)public class Create { Create() { System.out.print("1 "); } Create(int num) { System.out.print("2 "); } Create(Integer num) { System.out.print("3 "); } Create(Object num) { System.out.print("4 "); } Create(int... nums) { System.out.print("5 "); } public static void main(String[] args) { new Create(100); new Create(1000L); }}*A. The code prints out 2 4.B. The code prints out 3 4.C. The code prints out 4 2.D. The code prints out 4 4.E. The code prints 3 4 if you remove the constructor Create(int num).F. The code prints 4 4 if you remove the constructor Create(int num).G. The code prints 5 4 if you remove the constructor Create(int num).
Solution
The correct answers are:
A. The code prints out 2 4. - This is true. The first call to new Create(100) will call the constructor Create(int num) which prints out 2. The second call to new Create(1000L) will call the constructor Create(Object num) which prints out 4.
F. The code prints 4 4 if you remove the constructor Create(int num). - This is also true. If you remove the constructor Create(int num), the first call to new Create(100) will now call the constructor Create(Object num) which prints out 4. The second call to new Create(1000L) will still call the constructor Create(Object num) which prints out 4.
Similar Questions
Which of the following are output by the following code? (Choose all that apply)public class StringBuilders { public static StringBuilder work(StringBuilder a, StringBuilder b) { a = new StringBuilder("a"); b.append("b"); return a; } public static void main(String[] args) { StringBuilder s1 = new StringBuilder("s1"); StringBuilder s2 = new StringBuilder("s2"); StringBuilder s3 = work(s1, s2); System.out.println("s1 = " + s1); System.out.println("s2 = " + s2); System.out.println("s3 = " + s3); } }*A. s1 = aB. s1 = s1C. s2 = s2D. s2 = s2bE. s3 = aF. s3 = nullG. The code does not compile.
What is the result of the following statements?1: public class Test {2: public void print(byte x) {3: System.out.print("byte");4: }5: public void print(int x) {6: System.out.print("int");7: }8: public void print(float x) {9: System.out.print("float");10: }11: public void print(Object x) {12: System.out.print("Object");13: }14: public static void main(String[] args) {15: Test t = new Test();16: short s = 123;17: t.print(s);18: t.print(true);19: t.print(6.789);20: }21: }*A. bytefloatObjectB. intfloatObjectC. byteObjectfloatD. intObjectfloatE. intObjectObjectF. byteObjectObject
What's the output from the following statements?public class Foo { static int i = 0; static int j = 0; public static void main(String[] args) { int i = 2; int k = 3; { int j = 3; System.out.println("i + j is " + i + j); } k = i + j; System.out.println("k is " + k); System.out.println("j is " + j); }}
Which of the following calls to this method are valid?A. printVarargs("Hello", "World"); B. printVarargs({"Hello", "World"}); C. printVarargs(new String[]{"Hello", "World"}); D. printVarargs(new String[]{"Hello"}, "World"); a. A and B b. B and C c. A and C d. C and D
Given1. class Pro{2. 3. public static void main(String args[]){4. System.out.print(new A(5).y);5. System.out.print(new A().x);6. } 7. } 8. 9. class A{10. A(int i){11. y = i;12. System.out.print("A");13. super();14. }15. int y;16. int x = 10;17. } 18. Which is the output?*A510Compilation fails due to multiple errors.Compilation fails due to an error on line 5.A5 followed by an exception.Compilation fails due to an error on line 13.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.