When a class (say class1) inherited form another class (Class0).
The constructor in the class0 will be executing before the constructor of
class1.
Can we over the constructor? 7 37870
Depends on what kind of constructor it is - if it is the default constructor
(i.e. constructor with no parameters) then you can't override the parent's
constructor, it will always execute. If it is a non-default constructor then
it is automatically overriden unless you call it using the "base" keyword.
Note that the default constructor of the parent is always called regardless
of what kind of constructor is being invoked of the child class. Also,
whenever a base-class constructor executes, it does so before the inherited
class constructor is run.
Hope that helps,
~amit
"ad" <ad@wfes.tcc.ed u.tw> wrote in message
news:uJ******** ******@TK2MSFTN GP09.phx.gbl... When a class (say class1) inherited form another class (Class0).
The constructor in the class0 will be executing before the constructor of class1.
Can we over the constructor?
Amit wrote: Note that the default constructor of the parent is always called regardless of what kind of constructor is being invoked of the child class.
No, this is not true. You can specify which base constructor will be
called -
public ThisType(t1 p1, t2 p2): base(p1) { /*...*/ }
--
programmer, author http://www.midnightbeach.com
and father http://www.midnightbeach.com/hs
oops you're right... the default constructor of the parent class is always
called IF no other constructor is specified.
"Jon Shemitz" <jo*@midnightbe ach.com> wrote in message
news:41******** *******@midnigh tbeach.com... Amit wrote:
Note that the default constructor of the parent is always called
regardless of what kind of constructor is being invoked of the child class.
No, this is not true. You can specify which base constructor will be called -
public ThisType(t1 p1, t2 p2): base(p1) { /*...*/ }
--
programmer, author http://www.midnightbeach.com and father http://www.midnightbeach.com/hs
ad <ad@wfes.tcc.ed u.tw> wrote: When a class (say class1) inherited form another class (Class0).
The constructor in the class0 will be executing before the constructor of class1.
Can we over the constructor?
You can't override constructors, because they aren't inherited. It's
not entirely clear what you're after, but the following page may help: http://www.pobox.com/~skeet/csharp/constructors.html
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Amit wrote: oops you're right... the default constructor of the parent class is always called IF no other constructor is specified.
Yes, this is better. A base constructor will always be called, for
every class that descends from object, because every class must have
at least one constructor that calls a base() constructor (explicitly
or implicitly) and every call to a this() constructor must ultimately
call a base() constructor.
--
programmer, author http://www.midnightbeach.com
and father http://www.midnightbeach.com/hs
"Jon Shemitz" <jo*@midnightbe ach.com> wrote in message
news:41******** *******@midnigh tbeach.com... A base constructor will always be called, for every class that descends from object, because every class must have at least one constructor that calls a base() constructor (explicitly or implicitly)
And because, one way or another, the base object must be constructed.
--
Truth,
James Curran
[erstwhile VC++ MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
James Curran wrote: "Jon Shemitz" <jo*@midnightbe ach.com> wrote in message news:41******** *******@midnigh tbeach.com...
A base constructor will always be called, for every class that descends from object, because every class must have at least one constructor that calls a base() constructor (explicitly or implicitly)
And because, one way or another, the base object must be constructed.
Yes. That's the semantic reason for the syntactic requirement.
--
programmer, author http://www.midnightbeach.com
and father http://www.midnightbeach.com/hs This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ruben Van Havermaet |
last post by:
Hi,
I have a problem using member functions in derived classes that
override virtual member functions of base classes.
The following pieces of (simplified) code don't work. Can anybody give
me some hints on what might be wrong?
// BEGIN OF SAMPLE CODE
class Strategy
|
by: Ben Blank |
last post by:
I'm writing a family of classes which all inherit most of their methods and
code (including constructors) from a single base class. When attempting to
instance one of the derived classes using parameters, I get CS1501 (no method
with X arguments). Here's a simplified example which mimics the
circumstances:
namespace InheritError {
// Random base class.
public class A {
protected int i;
|
by: Josef Meile |
last post by:
Hi,
I have this constructor:
public CExcelDatabase(string host, string user, string password, string
database,
bool promptCredentials, int
findExcelInstance, bool readOnly)
{
//Some code comes here
|
by: TJS |
last post by:
How can I override the default values, of a class constructor , from an
ASP.net page ?
Public Sub New( )
HeaderStyle.BackColor = ColorTranslator.FromHtml("#5C85AD")
HeaderStyle.ForeColor = Color.White
HeaderStyle.Font.Bold = True
End Sub
|
by: RickHodder |
last post by:
I'm having a problem, and here is a simplified example of code that
demonstrates it:
public class BizObj
{
public string TableName="";
private DataSet oData;
public BizObj()
| |
by: TarheelsFan |
last post by:
What happens whenever you throw an exception from within a constructor?
Does the object just not get instantiated?
Thanks for replies.
|
by: slolife |
last post by:
See any problem with this code:
Here's my Base page class:
Public Class BasePage
Inherits System.Web.UI.Page
Protected m_NeedAlerts As Boolean
Private Sub Page_Init(ByVal sender As Object, ByVal e As
|
by: Smithers |
last post by:
I have some logic that populates UI controls with values from App.config. A
couple of checkboxes get checked or unchecked; and items loaded into a
checked list box.
Two reasonable places to put this code:
1. the form's constructor (or in a method called from within the
constructor)
2. the Form_Load event procedure
What are the important considerations or tradeoffs entailed by those two
|
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,...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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();...
|
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...
|
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
| |