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

  • Home
  • SEARCH
  • 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 8271515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:52:08+00:00 2026-06-08T06:52:08+00:00

I come from a Java background. Please have a look at the code below

  • 0

I come from a Java background. Please have a look at the code below (example taken from a Java book I once read and the code converted into .NET):

Public Class Animal
    Public Overridable Sub Eat()
        MsgBox("Animal Eat no arguement")
    End Sub
End Class

Public Class Horse
    Inherits Animal
    Public Overrides Sub Eat()
        MsgBox("Horse Eat no arguement")
    End Sub
    Public Overloads Sub Eat(ByVal food As String)
        MsgBox("Horse Eat food arguement")
    End Sub
End Class

Public Class Form1

    Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim a1 As New Animal
        Dim a2 As New Horse
        a1.Eat()
        a2.Eat() 
        a2.Eat("Fruit") 'line 5
    End Sub
End Class

I would expect line 5 of the form_load to produce a compile time error. In Java the compiler would look at the reference and see that Animal does not have an Eat method that takes a String. Why is there no compile error in .NET?

Update
There is an error in the code above. As the answerer points out; a2 is a reference to and an instance of Horse. Hence why line 5 does not cause a compile time error. If a2 referenced an animal and created an instance of a horse then there would be a compile time error (consistent with Java)

  • 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-08T06:52:10+00:00Added an answer on June 8, 2026 at 6:52 am

    You are overloading eat() with a version that accepts a string arg in the horse class. That is entirely valid.

    An overload is a method with the same name but different arguments. Your overloaded eat(string) is perfectly valid and works just fine when called on an object and reference of type horse.

    You could not call it on an object or reference of type animal, though.

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

Sidebar

Related Questions

I come from Java Background and so used to Debugging using Eclipse but have
I come from a Java background and have been using C# for the last
I come from Java background, where we have data structures with interfaces that if
I have no experience in C++, and I come from a Java background. Lately,
I am using C# having come from a Java background - I have an
I come from a strong Java background and in recent years have been also
I come from a C/Java background where switch cases have a cascading effect unless
I come from a Java background and am getting more into .NET, what are
I've come from a java background, so i'm still getting to grips with some
I'm new to PHP but come from a Java background and I'm trying to

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.