473,606 Members | 3,100 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overriding my method

Hi,
I have two classes. Class2 inhertis Class1:
-----------------------------
Public Class Class1
Public Overridable Sub MySub()

End Sub
End Class

Public Class Class2
Inherits Class1
Public Overrides Sub MySub()

End Sub
End Class
-----------------------------
When I write MySub with another signature in Class1, MySub in Class2 becomes
underlined and indicates an error:
-----------------------------
Public Class Class1
Public Overridable Sub MySub()

End Sub
Public Overridable Sub MySub(ByVal i As Int16)

End Sub
End Class

Public Class Class2
Inherits Class1
Public Overrides Sub MySub()

End Sub
End Class
-----------------------------
I know that I can fix it by adding Overloads keyword to MySub in Class2, but
I want to know the reason that why it's not possible to override it without
overloading?
Any help would be greatly appreciated.
Amin
Nov 21 '05 #1
3 1536
Overriding is basically changing the way the method/property behaves; you
cannot change the signature of a method/property when overriding. Take a
look at this document for rules on overriding:
http://msdn.microsoft.com/library/de...ingmethods.asp

To change the signature, you will have to use the Overloads keyword.

hope that helps..
Imran.

"Amin Sobati" <am***@morva.ne t> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi,
I have two classes. Class2 inhertis Class1:
-----------------------------
Public Class Class1
Public Overridable Sub MySub()

End Sub
End Class

Public Class Class2
Inherits Class1
Public Overrides Sub MySub()

End Sub
End Class
-----------------------------
When I write MySub with another signature in Class1, MySub in Class2 becomes underlined and indicates an error:
-----------------------------
Public Class Class1
Public Overridable Sub MySub()

End Sub
Public Overridable Sub MySub(ByVal i As Int16)

End Sub
End Class

Public Class Class2
Inherits Class1
Public Overrides Sub MySub()

End Sub
End Class
-----------------------------
I know that I can fix it by adding Overloads keyword to MySub in Class2, but I want to know the reason that why it's not possible to override it without overloading?
Any help would be greatly appreciated.
Amin

Nov 21 '05 #2
Thanks Imran,
But I think I don't manipulate it's signature. If my overriding is
considered as signature change, then why it is not for the first
situation(when there are one MySub in Class1, instead of two overloaded)? In
the first code the I pasted here, I can override without any problem.
Problem occurs as I add another MySub(with different signature) to Class1.
Amin
"Imran Koradia" <no****@microso ft.com> wrote in message
news:#n******** ******@TK2MSFTN GP15.phx.gbl...
Overriding is basically changing the way the method/property behaves; you
cannot change the signature of a method/property when overriding. Take a
look at this document for rules on overriding:
http://msdn.microsoft.com/library/de...us/vbcn7/html/
vaconoverriding existingmethods .asp
To change the signature, you will have to use the Overloads keyword.

hope that helps..
Imran.

"Amin Sobati" <am***@morva.ne t> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi,
I have two classes. Class2 inhertis Class1:
-----------------------------
Public Class Class1
Public Overridable Sub MySub()

End Sub
End Class

Public Class Class2
Inherits Class1
Public Overrides Sub MySub()

End Sub
End Class
-----------------------------
When I write MySub with another signature in Class1, MySub in Class2

becomes
underlined and indicates an error:
-----------------------------
Public Class Class1
Public Overridable Sub MySub()

End Sub
Public Overridable Sub MySub(ByVal i As Int16)

End Sub
End Class

Public Class Class2
Inherits Class1
Public Overrides Sub MySub()

End Sub
End Class
-----------------------------
I know that I can fix it by adding Overloads keyword to MySub in Class2,

but
I want to know the reason that why it's not possible to override it

without
overloading?
Any help would be greatly appreciated.
Amin


Nov 21 '05 #3
Sorry - my mistake. I misunderstood the problem. When you add another MySub
with different signature to Class1, you'll have to use the overloads keyword
there. So your two classes should look something like:

Public Class Class1
Public Overridable Overloads Sub MySub()

End Sub
Public Overridable Overloads Sub MySub(ByVal i As Int16)

End Sub
End Class

Public Class Class2
Inherits Class1
Public Overrides Sub MySub()

End Sub
End Class

I think you should be fine then. However, if you are going to override the
MySub with the new signature as well, then I think you don't need the
Overrides keyword anymore. Only the Overloaded is needed. Something like:
Public Class Class1
Public Overridable Overloads Sub MySub()

End Sub
Public Overridable Overloads Sub MySub(ByVal i As Int16)

End Sub
End Class

Public Class Class2
Inherits Class1
Public Overloads Sub MySub()

End Sub

Public Overloads Sub MySub(ByVal i As Int16)

End Sub
End Class

However, I'm not absolutely sure of that but I do remember reading that
somewhere. You can try with the Overrides or without it and see which one
works. But yes - the first piece of code should resolve what you are looking
for.

hope that helps..
Imran.

"Amin Sobati" <am***@morva.ne t> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Thanks Imran,
But I think I don't manipulate it's signature. If my overriding is
considered as signature change, then why it is not for the first
situation(when there are one MySub in Class1, instead of two overloaded)? In the first code the I pasted here, I can override without any problem.
Problem occurs as I add another MySub(with different signature) to Class1.
Amin
"Imran Koradia" <no****@microso ft.com> wrote in message
news:#n******** ******@TK2MSFTN GP15.phx.gbl...
Overriding is basically changing the way the method/property behaves; you cannot change the signature of a method/property when overriding. Take a
look at this document for rules on overriding:

http://msdn.microsoft.com/library/de...us/vbcn7/html/ vaconoverriding existingmethods .asp

To change the signature, you will have to use the Overloads keyword.

hope that helps..
Imran.

"Amin Sobati" <am***@morva.ne t> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi,
I have two classes. Class2 inhertis Class1:
-----------------------------
Public Class Class1
Public Overridable Sub MySub()

End Sub
End Class

Public Class Class2
Inherits Class1
Public Overrides Sub MySub()

End Sub
End Class
-----------------------------
When I write MySub with another signature in Class1, MySub in Class2

becomes
underlined and indicates an error:
-----------------------------
Public Class Class1
Public Overridable Sub MySub()

End Sub
Public Overridable Sub MySub(ByVal i As Int16)

End Sub
End Class

Public Class Class2
Inherits Class1
Public Overrides Sub MySub()

End Sub
End Class
-----------------------------
I know that I can fix it by adding Overloads keyword to MySub in
Class2, but
I want to know the reason that why it's not possible to override it

without
overloading?
Any help would be greatly appreciated.
Amin



Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3784
by: Andrew Durdin | last post by:
In Python, you can override the behaviour of most operators for a class, by defining __add__, __gt__, and the other special object methods. I noticed that, although there are special methods for most operators, they are conspicuously absent for the logical "or" and "and". I'm guessing that the reason for this is that these operators short-circuit if their first operand answers the whole question? Would it be possible to allow...
3
4177
by: Ali Eghtebas | last post by:
Hi, I have 3 questions regarding the code below: 1) Why can't I trap the KEYDOWN while I can trap KEYUP? 2) Is it correct that I use Return True within the IF-Statement? (I've already read the documentation but it is rather hard to understand so please don't refer to it :) 3) Many examples in the newsgroups use Return MyBase.ProcessKeyPreview(m) as the last code line while I have used Return MyBase.ProcessKeyEventArgs(m)
9
6329
by: James Marshall | last post by:
I'm writing a library where I want to override document.write(), but for all document objects; thus, I want to put it in the prototype. I tried Document.prototype.write= my_doc_write ; but it didn't work. I discovered that this seemed to work: HTMLDocument.prototype.write= my_doc_write ; Why does HTMLDocument work here but not Document? Will this second
4
1923
by: ORi | last post by:
Hi all ! There's a question I've been bothering for a while: I'm actually developing architectural frameworks for application developing and I think virtual methods, although needed because of the flexibility they introduce (flexibility really needed in framework developing), are often a nuisance for final developers. They don't like them because they never know if base class must be called and where should they place the call if...
17
2906
by: Bob Weiner | last post by:
What is the purpose of hiding intead of overriding a method? I have googled the question but haven't found anything that makes any sense of it. In the code below, the only difference is that when the Poodle is upcast to the Dog (in its wildest dreams) it then says "bow wow" where the bernard always says "woof" (see code). Basically, it appears that I'm hiding the poodle's speak method from everything except the poodle. Why would I...
6
5405
by: John Cobb | last post by:
MSDN and intellisense shows the Add method of Hashtable being overridable however when I use this code: Public Class RAL Inherits Hashtable Public Overrides Sub Add(ByVal Key As String, ByVal Value As Object) End Sub
6
27791
by: bryanbabula | last post by:
I have a question about overriding i was wondering if anyone could help me with, or even suggesting a better/different way. I have no idea if this can even be done or not. I was wondering if there was anyway to force a class to call a base class's method that it is overriding? Almost the same way you have to call a base class's constructor if it has arguments. (example ** assuming the Person class's constructor has (string FirstName) as...
10
105171
by: r035198x | last post by:
The Object class has five non final methods namely equals, hashCode, toString, clone, and finalize. These were designed to be overridden according to specific general contracts. Other classes that make use of these methods assume that the methods obey these contracts so it is necessary to ensure that if your classes override these methods, they do so correctly. In this article I'll take a look at the equals and hashCode methods. ...
5
2720
by: kj | last post by:
I'm trying to subclass file, overriding the readline method. The new method definition begins with def readline(self, size=None): line = self.file.readline(size) # etc., etc. ....where the self.file attribute is a regular file object. This works fine if I invoke the new method with an integer argument,
0
8036
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8461
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8448
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8317
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5987
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5470
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2454
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1572
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1313
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.