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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:24:08+00:00 2026-05-26T05:24:08+00:00

// Casting of class ArrayList a1 = new ArrayList<Integer>(); Number n1 = (Number)a1; //

  • 0
    // Casting of class
    ArrayList a1 = new ArrayList<Integer>();
    Number n1 = (Number)a1; // clause 1 Error 
    AdjustmentListener c1 = (AdjustmentListener)a1; // Clause 2 No error
    EventListener c3 = (EventListener)a1; // Clause 3 No error

Based on the above, clause 1 has error. Logical. There is no relation between those 2 classes. For clause 2, there is no relation between an arrayList (a class) and the adjustmentlistener interface. Why is there no error?

EDIT 1:

    String str1 = new String();
    AdjustmentListener c2 = (AdjustmentListener)str1; // clause 4 compiler error
  • 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-26T05:24:08+00:00Added an answer on May 26, 2026 at 5:24 am

    In order for a cast to succeed, there must be some possible implementer of both arguments. Take, for example, the following imaginary class declarations:

    
    5: class ComparableArrayList extends ArrayList implements Comparable
    7: class NumberList extends Number implements List
    8: class ComparableList implements Comparable, List
    

    An instance of each would allow the cast to succeed. For clause 4, in order for the cast to work, you would need

    
    class NumberArrayList extends ArrayList, Number
    

    and Java does not allow multiple inheritance.

    EDIT for edited question:

    In clause 1, there is no possible relationship between the classes, because you cannot have a class extend both ArrayList and Number. In clauses 2 and 3, it is possible to create a relationship by creating a new class that extends ArrayList and implements AdjustmentListener. Then set a1 to an instance of that class.

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

Sidebar

Related Questions

Since PHP has no custom-class type-casting, how would I go about doing the PHP
Run time exception-- java.lang.ClassCastingException ... Integer intArr[] = new Integer[arrList.size()]; ArrayList <Integer> arrList =new
I have a generic class that I'm trying to implement implicit type casting for.
How do I provide support for casting my class to other types? For example,
How to implement casting to a private base class in C++? I don't want
I am quite new to Java ... I wrote a class called DLPFile which
I am using a derived class and casting the base class to it using
When speaking about casting here, I mean implicit cast. Assume class B inherits from
Is it appropriate to access a class' private members by casting it to a
I have this code sample: class Number { int i; public: Number(int i1): i(i1)

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.