Question: Consider the following code. For each line with a blank label it with the vocabulary term that BEST describes it. The vocabulary terms are at
Consider the following code. For each line with a blank label it with the vocabulary term that BEST describes it. The vocabulary terms are at the bottom of the page and each term is used only once.
public class Foo {
____private List
____public Foo() {
____x = new ArrayList
____x.add(5);
}
public int method1() {
____return x.get(0);
}
}
____ public class Bar extends Foo {
public Bar() {
super();
}
____public int method1() {
return 1;
}
____ public int method1(int x) {
return x;
}
}
Vocabulary terms:
a. Accessor/Getterb. Constructorc. Mutator/Setterd. Interface
e. Overridingf. Polymorphismg. Inheritanceh. Overloading
For each of the following questions, circle the best answer or answers that apply.If the question does not ask you to mark ALL that apply, you should assume there is only one answer. (YY points each)
1.Assume class Parallelogram is a child (subclass) of class Quadrilateral and that Quadrilateral has a method foo.Which of the following method calls are wrong?(Mark ALL that apply)
a.Quadrilateral q = new Parallelogram(); q.foo();
b.Parallelogram q = new Parallelogram(); p.foo();
c.Object o = new Parallelogram(); o.foo();
2.What value does the variable foo have at the end of this segment of code?
ArrayList
bar.add(1); bar.add(2); bar.add(3);
int i = 0;
while (i < 3) {
int x = bar.remove(0);
bar.add(i,2*x);
i++;
}
int foo = bar.get(2);
a.1
b.6
c.4
d.The loop will never terminate
3.Which of the following are true about classes in Java (Mark ALL that apply)?
a.A class inherits the public fields of its parent class.
b.A class inherits the private methods of its parent class.
c.A class inherits the public methods of its parent class.
d.A class inherits the constructors of its parent class.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
