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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:20:27+00:00 2026-06-16T12:20:27+00:00

I am confused about the code below. This code is written by someone else

  • 0

I am confused about the code below. This code is written by someone else and I am currently studying the code to make more sense of how parameter-passing works in Java.

Does code #1

addKeyListener((KeyListener)new TAdapter());

and code #2

addKeyListener(new TAdapter());

mean the same thing and perform the same thing assuming TAdapter is a class that extends the KeyAdapter class? I also notice I do not necessarily have to explicitly cast the TAdapter object as a KeyListener even though from the method description I read in Eclipse the method takes in a KeyListener object. Why is this possible?
I did a quick search on the KeyAdapter class from Java docs and apparently the KeyAdapter class implements the KeyListener interface.
So am I safe to assume that one of the way Java works in parameter passing is that the method can accept an instance of a class that inherits from a certain class that implements an interface of the same name listed in the method description? If this is so, why is this also possible?

P.S. On a side note, I do not understand why the programmer name the class TAdapter, what does the T stand for? I also notice this type of class naming in other source code, but I never understood this supposed convention.

  • 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-16T12:20:29+00:00Added an answer on June 16, 2026 at 12:20 pm

    Well, yes, it is true that “the method can accept an instance of a class that inherits from a certain class that implements an interface”.

    More generally, a class that implements an interface can be said to be a subclass of that interface in terms of polymorphism, and any parameter or variable can be assigned an instance of any subclass of its declared class.

    As for why that class is named TAdapter, I’m afraid I can’t answer. It’s not any generally used convention, at least. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've encountered this Knockout code and I'm confused about what the below code is
I am confused about why this code says JPEG files and PNG files are
I'm somewhat confused about the code below: class BooksTestDrive { public static void main(String
I am kind of confused about how the below code works. In my head
I am confused about the LinkedList. They do not really make sense to me.
I am really really confused about Parallel.ForEach... How does it work? The code below
I am confused about getchar() 's role in the following code. I mean I
I'm confused about the errors generated by the following code . In Derived::doStuff, I
I am confused about how this XSLT apply-template statement works for cd/title/artist elements in
I know there are few threads about this topic. But what really confused me

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.