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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:50:33+00:00 2026-06-12T18:50:33+00:00

Computer[] labComputers = new Computer[10]; with public class Computer { … void toString(){ //

  • 0
Computer[] labComputers = new Computer[10];

with

public class Computer {
...
     void toString(){
     // print computer specs
     }
}
public class Notebook extends Computer{
...
     void toString(){
     // print computer specs + laptop color
     }
}

each subscripted variable labComputers[i] can reference either a Computer object or a Notebook object because Notebook is a subclass of Computer. For the method call labComputers[i].toString(), polymorphism ensures that the correct toString method is called.

I wonder what if we do

Notebook[] labComputers = new Notebook[10];

what kind or error would I get if I reference with Computer object and a Notebook object

  • 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-12T18:50:34+00:00Added an answer on June 12, 2026 at 6:50 pm

    Since the question specifically asks about kind of error I will explain them with below scenarios

    If you do below

    Notebook[] labComputers = new Notebook[10];
    

    Now you can only set Notebook objects in array.

    labComputers[0]  = new Notebook(); // Fine
    labComputers[1]  = new Computer(); // Compilation error 
    

    Now if you do

    Computer[] notebooks = new Notebook[10];
    notebooks[0] = new Notebook();
    notebooks[1] = new Computer(); // <--- ArrayStoreException
    

    Because arrays are covarant,reified in nature ie. if Sub is a subtype of Super, then the array type Sub[] is a subtype of Super[], and arrays enforce their element types at run time it will cause ArrayStoreException

    You can read oracle docs about Polymorphism to know more how it works.

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

Sidebar

Related Questions

On computer A I created 2 ssh keys, public and private. The public key
I took Computer Architecture course and I understood that processor has 32 registers each
I have a Computer with 5 interfaces: 3 with public IPs and 2 local
On Computer A (my computer), I have a Perl script that accesses a file
The computer is connected to measuring device via a physical COM1. I have simple
While computer programming evangelists predicting the future of Cloud Computing to be very bright,
Are computer languages copyrighted or have some restrictions imposed on them how they can
My computer is running behind proxy. I want to access url from JavaFX. for
have 2 questions : A computer with 32-bit address uses 2-level page table (9
I'm beginning a computer vision project and I need to compute the horizontal and

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.