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 7496267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:33:00+00:00 2026-05-29T18:33:00+00:00

I want to extend a class as shown in the below example. While extending,

  • 0

I want to extend a class as shown in the below example.
While extending, I just want to change the type of one variable; declaring the same variable name with a different type will do this?

class Graph {
    LinkedList<Node> vertices;
}


class EntityGraph extends Graph {
    LinkedList<Entity> vertices; 
} 
  • 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-29T18:33:01+00:00Added an answer on May 29, 2026 at 6:33 pm

    First off, making you variable acces type “protected” rather then default would be better in this scenario (i.e, make it protected in Graph class, and protected or less restrictive in EntityGraphClass).

    Then you can type your Graph class such as :

    class Graph<T> {
    
    protected LinkedList<T> vertices;
    
    }
    

    then do a

    class EntityGraph extends Graph<Entity> {
         //no longer needed
        //LinkedList<Entity> vertices; 
    } 
    

    and you’ll get an implementation of the Graph class (in the EntityGraph class) that has a List of Entity types;

    If Entity extends Node, and you want the elements in the list to be of at least Node type, you can do:

    class Graph<T extends Node> {
    
        protected LinkedList<T> vertices;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say you have some 3rd-party library class that you want to extend, simply
I have a static class in a shared project, which I want to extend
In following code, I want to extend the behaviour of a class by deriving/subclassing
In Kohana 3, how can I override/extend a module class? E.g. I want to
I want to extend the basic ControlCollection in VB.NET so I can just add
I want to use object instances as modules/functors, more or less as shown below:
I want to create an abstract base class for all paramter-type classes to inherit
I want to access the values of latitude and longitude of one class in
I am creating one parent Activity(Class) and then want to extends this class to
I want to extend a WPF application with database functionality. Which database engine would

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.