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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:37:06+00:00 2026-06-17T02:37:06+00:00

Create a class with a generic type T . A subclass of the class

  • 0

Create a class with a generic type T. A subclass of the class that defines a second type parameter, called V. Call the methods from both classes using the object. Create 2 objects with different objects

This is the question.

This is not homework if anyone might think. I am doing some java papers for practice. I don’t understand how to “create 2 objects with different objects”. Can anyone help?

class Gen<T> 
 {
  T obj;
  Gen(T ob)
  {
    obj = ob;
  }

 T getobj()
  {
    return obj;
  }
}

class Gen2<T, V> extends Gen<T>
{
  V obj1;
  Gen2(T ob,V ob1)
   {
    super(ob);
    obj1 = ob1;
   }

 V getobj1()
 { 
    return obj1;
 }

}

public class Ch2Lu4Ex3 
 {
  public static void main(String args[]) 
    {
      Gen2<String,String> g = new Gen2<String,String>("robin","raj");        

      System.out.println(g.getobj1());
      System.out.println(g.getobj());
    }
 }
  • 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-17T02:37:07+00:00Added an answer on June 17, 2026 at 2:37 am

    Well, you could do things like:

    Gen<Integer> gen1 = new Gen<Integer>(10);
    Gen2<Integer> gen2 = new Gen2<Integer,String>(10,"Hello");
    

    Or you could combine them since they are on the same hierarchy.

    Gen<Integer> gen1 = new Gen2<Integer,String>(10,"Hello");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to create a generic class from type parameter. I have
How can I create a generic class, which takes the class type from the
I'am trying to create a generic class that contains a list of generic type
I'm trying to create an instance of a generic class using a Type object.
I'm trying to create a generic class in PHP that will provide a way
Please explain what this task is about? Create a generic linked list class that
Possible Duplicate: Create instance of generic type in Java? I got these classes public
Trying to create a static field with a generic type doesn't compile: class MyClass
I have an interesting problem. I'd like to create a generic class that can
There is a class with generic type: class Action[T] Create some instances of it,

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.