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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:01:38+00:00 2026-06-15T14:01:38+00:00

So I am a student and in the process of learning Java. There is

  • 0

So I am a student and in the process of learning Java. There is one concept that I am having a difficult time grasping and am hoping that someone could shed some light on this for me. My question is regarding polymorphism. Let’s say for example I have the following code.

Animal a = new Lizard("Lizzy", 6);  //Lizard extends Animal
  1. From what I understand, since the variable type is Animal, a will have all the characteristics of an Animal. But, since the object created is a Lizard, any overridden methods in the Lizard class will be used instead of those in the Animal class. Is this correct>

  2. Also, which classes constructor will be used while creating a?

Thanks for any help. I have looked quite

  • 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-15T14:01:40+00:00Added an answer on June 15, 2026 at 2:01 pm

    1.From what I understand, since the variable type is Animal, a will have all the characteristics of an Animal. But, since the object
    created is a Lizard, any overridden methods in the Lizard class will
    be used instead of those in the Animal class. Is this correct>

    yes, you are Right.

    2.Also, which classes constructor will be used while creating a?

              Animal a = new Lizard("Lizzy", 6);  //Lizard extends Animal
    

    As, Lizard is a subclass of Animal, First, Lizards constructor will be invoked, then from Lizards constructor, there will be a call to Animal constructor as the first line in your Lizard constructor would be super() by default unless you call an overloaded constructor of Lizard using this(). In Animal constructor there will be another call to super() in the first line. assuming Animal doesn’t extend any class, java.lang.Object's constructor will be invoked as java.lang.Object is the super class of every object.

      public Object() {
    
        }
        Class Animal {
         public Animal(){
          //there will be a super call here like super()
        }
    
        class lizard extends Animal {
        public Lizard(your args) {
           //there will be a super() call here and this call's animal's no-args constructor
         }
        }
    
     }
    

    The order of execution would be

    1. Lizards constructor will be invoked
    2. unless there is a this() call to an overloaded constructor, a call to super() i.e., call’s Animals no-args Constructor
    3. java.lang.Object’s Constructor will be invoked from animal using super()
    4. java.lang.Object’s constructor code will execute
    5. Animals constructor code will execute
    6. Lizards constructor code will execute
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering is learning Python and Django a hard/time consuming process for someone
In my iPhone application, there is one options to pick a student name from
I'm a student just learning xml and c#. I'm writing a program that will
New to MVC and RoR and having a hard time grasping some of the
I have a table student ( id, name ). Then I have one textbox,
I have a database table which gets updated by a process from time to
I am a co-op student learning vb.net and I have a project which retrieves
As a student of computational linguistics, I frequently do machine learning experiments where I
I want to create one Online Exam System where student can attend Exam and
I need to process few lines of code over and over in RFT (java)

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.