Driver Class and Object Interaction
Consider the two classes shown below. Which of the following statements accurately describes the code?
public class Driver {
public static void main(String[] args) {
Calculator calc = new Calculator();
System.out.println(calc.add(5, 7));
}
}
public class Calculator {
public int add(int a, int b) {
return a + b;
}
}
A
A main method that attempts to call ‘add’ without creating a Calculator instance.
B
A Driver class that does not instantiate any objects.
C
A Calculator class with the main method calling its ‘add’ method.
D
A Driver class with a main method that instantiates a Calculator object and calls its ‘add’ method.
Question Leaderboard
Not enough data yet to show leaderboard.
