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

  • SEARCH
  • Home
  • 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 7834475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:10:52+00:00 2026-06-02T13:10:52+00:00

I am reading some code in Java, which I am not familiar with, but

  • 0

I am reading some code in Java, which I am not familiar with, but it seems weird that if a class is Deck (for a deck of cards), it already has an instance variable of an array of Cards, so why does Deck extend or inherit Card? I thought class A inherits class B only if A is a B (Cat inherits Animal because a cat is an animal).

The code is below:

public class Deck <T extends Card> {
    private ArrayList<T> cards;
    private int dealtIndex = 0; // marks first undealt card

    public Deck() {
    }

    public void setDeckOfCards(ArrayList<T> deckOfCards) {
        cards = deckOfCards;
    }

    public void shuffle() {
        for (int i = 0; i < cards.size(); i++) {

    [...]
}

public abstract class Card {
    private boolean available = true;

    /* number or face that's on card - a number 2 through 10, 
     * or 11 for Jack, 12 for Queen, 13 for King, or 1 for Ace 
     */
    protected int faceValue;
    protected Suit suit;

    public Card(int c, Suit s) {
        faceValue = c;
        suit = s;
    }

    public abstract int value();

    public Suit suit() { 
        return suit; 
    }

    [...]

}
  • 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-06-02T13:10:54+00:00Added an answer on June 2, 2026 at 1:10 pm
     public class Deck <T extends Card> 
    

    Deck does not extend Card.

    This is a generic type annotation, and it says that a Deck can be of type T where T is a subclass of Card.

    This is the same as Java’s collection classes, where a List of String also does not extend String (but contains String instances).

    This allows you to write code like:

    Deck<PokerCard> pokerDeck = new Deck<PokerCard>();
    
    PokerCard c = pokerDeck.getTopCard();   
    // now you know it is a PokerCard, not just any old card
    
    pokerDeck.insert(new MagicTheGatheringCard()); 
    // get a compile error for wrong card type
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which does nothing but reading some values from a
I'm reading some C code like that: double function( int lena,double xa,double ya, double
I'm reading some source code at https://github.com/plataformatec/devise and found that line of code: class_eval
Trying to port java code to C++ I've stumbled over some weird behaviour. I
After reading all sorts of Stackoverflow postings and various documentation including some on http://code.google.com/p/google-api-java-client/
I'm reading some code in the Ogre3D implementation and I can't understand what a
Reading some Verilog code, there seem to be two ways of defining arguments in
I have been reading over some code lately and came across some lines such
When reading some FreeBSD source code (See: radix.h lines 158-173), I found variable declarations
I have some code reading a text file and scanning for words between brackets:

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.