Consider this class:
1. public class Test1 {
2. public float aMethod(float a, float b) {
3. }
4.
5. }
Which of the following methods would be legal if added (individually) at line 4? (Choose
all
that apply.)
A. public int aMethod(int a, int b) { }
B. public float aMethod(float a, float b) { }
C. public float aMethod(float a, float b, int c) throws Exception { }
D. public float aMethod(float c, float d) { }
E. private float aMethod(int a, int b, int c) { } ** Answ** a,c,e
Consider these classes, defined in separate source files:
1. public class Test1 {
2. public float aMethod(float a, float b)
3. throws IOException {...
4. }
5. }
1. public class Test2 extends Test1 {
2.
3. }
Which of the following methods would be legal (individually) at line 2 in class Test2?
(Choose
all that apply.)
A. float aMethod(float a, float b) {...}
B. public int aMethod(int a, int b) throws Exception {...}
C. public float aMethod(float a, float b) throws Exception {...}
D. public float aMethod(float p, float q) {...} ** Answ** b,d
You have been given a design document for a veterinary registration system for
implementation
in Java. It states:
"A pet has an owner, a registration date, and a vaccination-due date. A cat is a pet that
has a
flag indicating whether it has been neutered, and a textual description of its markings."
Given that the Pet class has already been defined, which of the following fields would
be
appropriate for inclusion in the Cat class as members? (Choose all that apply.)
A. Pet thePet;
, B. Date registered;
C. Date vaccinationDue;
D. Cat theCat;
E. boolean neutered;
F. String markings; ** Answ** e,f
You have been given a design document for a veterinary registration system for
implementation
in Java. It states:
"A pet has an owner, a registration date, and a vaccination-due date. A cat is a pet that
has a
flag indicating if it has been neutered, and a textual description of its markings."
Given that the Pet class has already been defined and you expect the Cat class to be
used freely
throughout the application, how would you make the opening declaration of the Cat
class, up
to but not including the first opening brace? Use only these words and spaces: boolean,
Cat,
class, Date, extends, Object, Owner, Pet, private, protected, public, String.
A. protected class Cat extends Owner
B. public class Cat extends Object
C. public class Cat extends Pet
D. private class Cat extends Pet ** Answ** c
Consider the following classes, declared in separate source files:
1. public class Base {
2. public void method(int i) {
3. System.out.print("Value is " + i);
4. }
5. }
1. public class Sub extends Base {
2. public void method(int j) {
3. System.out.print("This value is " + j);
4. }
5. public void method(String s) {
6. System.out.print("I was passed " + s);
7. }
8. public static void main(String args[]) {
9. Base b1 = new Base();
10. Base b2 = new Sub();
11. b1.method(5);
12. b2.method(6);
13. }
14. }
What output results when the main method of the class Sub is run?
A. Value is 5Value is 6