Question: The following code segment will be used for the remaining questions. The code in the classes Bar and Foo is complete, and ExamI contains only

 The following code segment will be used for the remaining questions.
The code in the classes Bar and Foo is complete, and ExamI

The following code segment will be used for the remaining questions. The code in the classes Bar and Foo is complete, and ExamI contains only a partially completed main method (in other words there are no additional methods in the class Examl, but there could be more code in the main method). NOTE: Pay attention to the "None of the above" selections for these questions - they may require you to do additional work beyond just circling the answer. Also some of these questions may have more than one correct answer listed - you should mark ALL that apply in these cases (YY points each): public class Bar ( private int myInt; 5; } public Bar(){ myInt %3D public void methodl(int x) { myInt = x;} public int method2 (int x) { return 2*x; } public class Foo extends Bar{ public Foo() { super(); } public int method2 (int x) { return 4; } public class ExamI { public static void main(String[] args) { Bar aBar = new Bar(); Foo aFoo - new Foo (); // The rest of the code follows from this point 7. Which of the following BEST describes the relationship between the classes Bar and Foo and Object (Mark ALL that apply): a. Foo is a subclass of Bar. b. Bar is a subclass of Foo. c. Object is a subclass of Bar. d. Foo is a subclass of Object. 8. Which of the following lines will print out 5? (Mark ALL that apply) a. System.out.println(aBar.method2() + 1); b. System.out.println(aFoo.method2() + 1); c. System.out.println(aBar.method2() - 5); d. System.out.println(aFoo.method2) - 5); e. System.out.println(aBar.mylnt); f. System.out.printin(aFoo.myInt); 9. Given the code above, suppose we have the following method header in the class ExamI: public static int sampleMethod2 (Foo f) Which of the following are correct calls to the method sampleMethod2? (Mark ALL that apply) a. int x = sampleMethod2 (aBar); b. int x = sampleMethod2 (aFo0); c. int x = sampleMethod2(); d. None of the above calls are correct - in the space below provide a correct way to call this method from the main method of ExamI: 10. In the code above, what would be a correct way to call the method method2 in the Bar class from the main method of the class ExamI? (Mark ALL that apply): a. Bar.method2 (); b. method2 (); c. aBar.method2 (); d. None of the above - in the space below indicate what the correct syntax for invoking method2 would be: 11. Given only the code you can see above, what would be a correct way for the class ExamI to set my Int to 10? (Mark ALL that apply): a aBar.methodl (10); b. aFoo.method1 (10); c. aBar.myInt - 10; d. ExamI cannot set my Int to 10 10

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!