Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming Questions (Multiple Choice) ** Please only answer if you know it, not just copy and paste from another user. Please explain the answer.

Java Programming Questions (Multiple Choice)

** Please only answer if you know it, not just copy and paste from another user. Please explain the answer.

1) Given code:

public abstract class A{ }

public class B extends A

{

}

The following code sequence would correctly create an object reference of class A holding an object reference for an object of class B:

A c;

c = new B();

TRUE
FALSE

----------------------------------------------------------------------------------------------------------------------------------------

2) After the following code sequence is executed, what are the contents at ArrayList index 1 in a?

ArrayList a = new ArrayList();

a.add(7);

a.add(10);

a.add(21);

a.set(1,4);

a.remove(0);

a 10
b 7
c 4
d 21

-------------------------------------------------------------------------------------------------------------------------------------------------

3) For this question, consider the following two classes:

public abstract class C

{

public void foo1()

{

System.out.println("Hello foo1");

}

public abstract void foo2();

public abstract void foo3();

public void foo1Call()

{

foo1();

}

}

public class D extends C

{

public void foo2()

{

System.out.println("Hello foo2");

}

public void foo4()

{

System.out.println("Hello D foo4()");

}

}

Which of the following code sequences, if any, will successfully access private method foo1 in class C?

a

C c2 = new C();

c2.foo1();

b

C c2 ;

c2 = new D();

c2.foo1();

c

D d1 = new D();

d1.foo1();

d

C c1 = new D();

c1.foo1Call();

e None of the above

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genetic Databases

Authors: Martin J. Bishop

1st Edition

0121016250, 978-0121016258

More Books

Students also viewed these Databases questions

Question

Discuss the six most common reasons firms pursue growth.

Answered: 1 week ago