473,408 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How to execute parent class functions and then child's

How to execute functions in the parent class first and then functions
in the child class? For example, I have a parent class with functions
'ONE' and 'TWO' and child class has a function 'THREE'. How should I
declare classes so that all three functions are executed when child
class is called?

Class Parent
public function ONE
'code
end fuction

public function TWO
'code
end fuction
end class

Class Child
Inherites Parent

public function THREE
'code
end fuction
end class

Nov 21 '05 #1
7 1998
<ms****@yahoo.com> schrieb
How to execute functions in the parent class first and then
functions in the child class? For example, I have a parent class
with functions 'ONE' and 'TWO' and child class has a function
'THREE'. How should I declare classes so that all three functions
are executed when child class is called?

Class Parent
public function ONE
'code
end fuction

public function TWO
'code
end fuction
end class

Class Child
Inherites Parent

public function THREE
'code
end fuction
end class


public function THREE
ONE
TWO
end fuction
That's what you need?

Armin
Nov 21 '05 #2
Hi,

I don't know if I understood you.

However you can set in the Sub New of your parent class

\\\
Public Sub New
ONE
TWO
End Sub
///

I hope this was what you where after

Cor
Nov 21 '05 #3
After some thought, this is what I would like to have. I am sorry to
both of you.
I have a parent class and child class. When I execute function ONE
from child class, is it going to executes parent's code plus child's
code? How should I declare or inherite a classe so that it executes
parent's code and then child's code?

Example:
Class Parent

public function ONE
'Parent Code
end fuction
end class
Class Child
Inherites Parent

public function ONE
'Plus Child Code
end fuction
end class


msx...@yahoo.com Jun 6, 11:27 am show options

Newsgroups: microsoft.public.dotnet.languages.vb
From: msx...@yahoo.com - Find messages by this author
Date: 6 Jun 2005 08:27:48 -0700
Local: Mon,Jun 6 2005 11:27 am
Subject: How to execute parent class functions and then child's
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Report Abuse

How to execute functions in the parent class first and then functions
in the child class? For example, I have a parent class with functions
'ONE' and 'TWO' and child class has a function 'THREE'. How should I
declare classes so that all three functions are executed when child
class is called?

ms****@yahoo.com wrote:
How to execute functions in the parent class first and then functions
in the child class? For example, I have a parent class with functions
'ONE' and 'TWO' and child class has a function 'THREE'. How should I
declare classes so that all three functions are executed when child
class is called?

Class Parent
public function ONE
'code
end fuction

public function TWO
'code
end fuction
end class

Class Child
Inherites Parent

public function THREE
'code
end fuction
end class


Nov 21 '05 #4
Msxkim,

It depends if one is a function that always should be performed in that
class, than in the way as I wrote. Is it not standard in that class, than in
the way as Armin wrote.

Cor
Nov 21 '05 #5
<ms****@yahoo.com> schrieb
After some thought, this is what I would like to have. I am sorry
to both of you.
I have a parent class and child class. When I execute function
ONE from child class, is it going to executes parent's code plus
child's code? How should I declare or inherite a classe so that it
executes parent's code and then child's code?

Example:
Class Parent

public function ONE
'Parent Code
end fuction
end class
Class Child
Inherites Parent

public function ONE
'Plus Child Code
end fuction
end class

Class Child
Inherites Parent

public function ONE
MYBASE.one
'Plus Child Code
end fuction
end class
Armin
Nov 21 '05 #6
Bingo! both of you

Armin Zingler wrote:
<ms****@yahoo.com> schrieb
After some thought, this is what I would like to have. I am sorry
to both of you.
I have a parent class and child class. When I execute function
ONE from child class, is it going to executes parent's code plus
child's code? How should I declare or inherite a classe so that it
executes parent's code and then child's code?

Example:
Class Parent

public function ONE
'Parent Code
end fuction
end class
Class Child
Inherites Parent

public function ONE
'Plus Child Code
end fuction
end class

Class Child
Inherites Parent

public function ONE
MYBASE.one
'Plus Child Code
end fuction
end class
Armin


Nov 21 '05 #7
<ms****@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I have a parent class and child class. When I execute function
ONE from child class, is it going to executes parent's code plus
child's code?


It depends. ;-)

Given these :

Class Parent
Public Sub ONE()
Debug.Writeline( "Parent.ONE" )
End Sub
End Class

Class Child
Inherits Parent
End Class

then

Dim c As New Child
c.ONE()

will display "Parent.ONE" - the child class is simply "passing on" the
Parent class' functionality.

However, changing these classes a little :

Class Parent
Public Overridable Sub ONE()
Debug.Writeline( "Parent.ONE" )
End Sub
End Class

Class Child
Inherits Parent
Public Overrides Sub ONE()
Debug.Writeline( "Child.ONE" )
End Sub
End Class

then

Dim c As New Child
c.ONE()

now displays "Child.ONE". The Child mothod replaces (a.k.a.
Overrides) the Parent method.

<--
And, just to be /really/ confusing, try this and see what you get ...

DirectCast( c, Parent ).ONE() ' ;-)
-->

To get /both/ sets of code to run, you make the Child method
call the Parent one, as in

Class Child
Inherits Parent
Public Overrides Sub ONE()
MyBase.ONE()
Debug.Writeline( "Child.ONE" )
End Sub
End Class

which (finally) displays "Parent.ONE" followed by "Child.ONE".

HTH,
Phill W.
Nov 21 '05 #8

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

Similar topics

14
by: pablo | last post by:
Dear NewsGroupers, I am relatively new to OOP and cannet get my head around this problem. I have two classes. Class Child extends Parent. There is no constructor for the Child class. So when I...
5
by: Paul | last post by:
Hi all, Here is what I am trying to do. I have a parent class calling a child class. when one function in child class is called, i need to call parent class' function. How can I get parent class'...
5
by: Suzanne Vogel | last post by:
Hi, Given: I have a class with protected or private data members, some of them without accessor methods. It's someone else's class, so I can't change it. (eg, I can't add accessor methods to the...
9
by: Martin Herbert Dietze | last post by:
Hello, I would like to implement a callback mechanism in which a child class registers some methods with particular signatures which would then be called in a parent class method. In...
6
by: jalkadir | last post by:
Let's say that I have this class: class Parent{ private: char* str; public: const char* getStr(){return str;} }; And then I create a child class class Child{ private: std::string str;...
5
by: owais | last post by:
Hi, I have a problem, I want to implements Parent class interface methods in child class. for e.g -------------- Test1.vb ---------------- Imports System Imports System.Web.UI Imports...
5
by: Noozer | last post by:
I have two Classes in use in an ASP application... The first Class is named "ORDER". It represents one job order. It has a Delete method, among others, which deletes it from my database. The...
7
by: S. Lorétan | last post by:
Hi guys, Sorry for this stupid question, but I don't know why it isn't working. Here is my (example) code: namespace Test { class A { public string Label1; }
6
by: Sashi | last post by:
class parent{ Parent(){}; ~Parent(){}; } Child: public Parent{ Child(){}; ~Child(){};
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...
0
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,...
0
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...

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.