Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7503715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:19:48+00:00 2026-05-29T21:19:48+00:00

I am preparing for OCJP . I found a question in dump import java.util.*;

  • 0

I am preparing for OCJP. I found a question in dump

import java.util.*;
 public class G1 {
 public void takeList(List<? extends String> list) {
   // insert code here
 }
}

Which three code fragments, inserted independently at line 6, will compile? (Choose three.)

 A. list.add("foo");
 B. Object o = list;
 C. String s = list.get(0);
 D. list = new ArrayList<String>();
 E. list = new ArrayList<Object>();

Answer: B,C,D

I have a query that if List<? extends String that means it matches with String class and all the subclass of String class.

Can anyone justify the answer shown here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:19:48+00:00Added an answer on May 29, 2026 at 9:19 pm

    A is incorrect, because your list could be a List<SomeStringSubClass>, and it would thus be invalid to add a String to it. (I know String is final, but the compiler doesn’t care about it here).

    E is incorrect because a List<Object> can’t be assigned to a List<? extends String>, obviously, since the objects contained by a List<Object> don’t necessarily are of type String or of a subclass of String.

    The other three ones are OK:

    • B is OK because everything except primitives is a an Object in Java
    • C is OK because a List<? extends String> contains instances of String, or instances of a subclass of String. And an instance of a sublcass is also an instance of the superclass.
    • D is OK because an ArrayList<String> is a List<String>, and a List<String> is also a List<? extends String>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm preparing a class on Visual Basic 2005 targeting Visual Basic 6 programmers migrating
I'm preparing a class on Visual Basic 2005 targeting Visual Basic 6 programmers migrating
I'm preparing a string that will be eval 'ed. The string will contain a
Preparing for exam and got stuck at this question: Allowed operators are <<,+,& no
I am busy preparing for exams, just doing some old exam papers. The question
I am preparing and sending a JSON string from my PHP file to my
I'm preparing to do an .NET exam and I came across this question. I
I'm preparing to SCJP and looks like I don't understand class cast principles. class
I am preparing for an exam and studying questions. However I have one question
i'm preparing for an exam and I'm having a question that I hope someone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.