473,594 Members | 2,833 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 1534
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
3783
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
2905
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
5404
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
105152
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
7874
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8241
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...
1
7997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6646
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5402
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();...
0
3853
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3893
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2383
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
0
1203
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.