| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
About Exam
easy Solved by 2 students
Driver Class and Object Interaction
< Prev
Next >

Which of the following is an example of a driver class correctly calling an object class based on the notes?

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 Driver class with a main method that instantiates a Calculator object and calls its ‘add’ method.

B

A Calculator class with the main method calling its ‘add’ method.

C

A main method that attempts to call ‘add’ without creating a Calculator instance.

D

A Driver class that does not instantiate any objects.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy