Consider the classes shown below: public class Parent { public void doSomething(){/* Implementation not shown */} } public class Child extends Parent { public void doAnotherThing(){/* Implementation not shown */} } Which lines in the following code will compile without error? Child kid = new Child(); kid.doSomething(); // line 1 kid.doAnotherThing(); // line 2
Blog
Which of the following represents a good strategy regarding…
Which of the following represents a good strategy regarding cohesion and class dependencies?
Consider the following code snippet: public class Vehicle {…
Consider the following code snippet: public class Vehicle { . . . public void setVehicleClass(double numberAxles) { . . . } } public class Auto extends Vehicle { . . . public void setVehicleClass(int numberAxles) { . . . } } Which of the following statements is correct?
Which type of method modifies the object on which it is invo…
Which type of method modifies the object on which it is invoked?
Consider the classes shown below: public class Parent { priv…
Consider the classes shown below: public class Parent { private int value = 100; public int getValue() { return value; } } public class Child extends Parent { private int value; public Child(int number) { value = number; } public int getValue() { return value; } } What is the output of the following lines of code? Child kid1 = new Child(-14); Child kid2 = new Child(21); System.out.println(kid1.getValue() + ” ” + kid2.getValue());
Consider the following recursive code snippet: public int my…
Consider the following recursive code snippet: public int mystery(int n, int m) { if (n == 0) { return 0; } if (n == 1) { return m; } return m + mystery(n – 1, m); } What parameter values for n would cause an infinite recursion problem in the following method?
Consider the classes shown below: public class Parent { priv…
Consider the classes shown below: public class Parent { private int value = 100; public int getValue() { return value; } } public class Child extends Parent { private int value; public Child(int number) { value = number; } } What is the output of the following lines of code? Child kid = new Child(-14); Parent kid2 = new Child(21); System.out.println(kid.getValue() + ” ” + kid2.getValue());
Consider the recursive method myPrint shown in this code sni…
Consider the recursive method myPrint shown in this code snippet: public void myPrint(int n) { if (n < 10) { System.out.print(n); } else { int m = n % 10; System.out.print(m); myPrint(n / 10); } } What does this method do?
When an object is intended to set and manage properties, whe…
When an object is intended to set and manage properties, where should those properties be stored?
Complete the code for the calcPower recursive method shown b…
Complete the code for the calcPower recursive method shown below, which is intended to raise the base number passed into the method to the exponent power passed into the method: public static int calcPower(int baseNum, int exponent) { int answer = 0; if (exponent == 0) { answer = 1; } else { _______________________________________ } return answer; }