473,795 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overriding or Hiding.

dmjpro
2,476 Top Contributor
Look at my code carefully.....

Expand|Select|Wrap|Line Numbers
  1. class Super
  2. {
  3.    protected int a;
  4. }
  5. class Derived extends Super
  6. {
  7.  protected int a; //Here Data Overriding or Data Hiding
  8. }
  9.  
Let's look at another example .....

Expand|Select|Wrap|Line Numbers
  1. class Super
  2. {
  3.  public static void test()
  4.  {
  5.     //Some content
  6.  }
  7. }
  8. class Derived extends Super
  9. {
  10.  public static void test() //Here Method Overriding or Method Hiding
  11.  {
  12.    //Some content
  13.  }
  14. }
  15.  
Plz explain .... Hiding and Overrinding for Method and Data ... for both.

Kind regards,
Dmjpro.
Jun 5 '07 #1
4 2359
r035198x
13,262 MVP
Look at my code carefully.....

Expand|Select|Wrap|Line Numbers
  1. class Super
  2. {
  3. protected int a;
  4. }
  5. class Derived extends Super
  6. {
  7. protected int a; //Here Data Overriding or Data Hiding
  8. }
  9.  
Let's look at another example .....

Expand|Select|Wrap|Line Numbers
  1. class Super
  2. {
  3. public static void test()
  4. {
  5. //Some content
  6. }
  7. }
  8. class Derived extends Super
  9. {
  10. public static void test() //Here Method Overriding or Method Hiding
  11. {
  12. //Some content
  13. }
  14. }
  15.  
Plz explain .... Hiding and Overrinding for Method and Data ... for both.

Kind regards,
Dmjpro.
But we've talked about this before, dj. Remember the difference between a class variable and an instance variable.
Jun 5 '07 #2
dmjpro
2,476 Top Contributor
But we've talked about this before, dj. Remember the difference between a class variable and an instance variable.
Ok.
I know we have discussed before.
But it would be better if u discuss again.
Plz.

Kind regards,
Dmjpro.
Jun 5 '07 #3
r035198x
13,262 MVP
Ok.
I know we have discussed before.
But it would be better if u discuss again.
Plz.

Kind regards,
Dmjpro.
You can't override a static

Have a look at the examples in the JLS and decide ...
Jun 5 '07 #4
JosAH
11,448 Recognized Expert MVP
Only non-static methods can be overridden (if they're not final). Everything else
can just be hidden. All methods can be overloaded but that is something completely
different.

kind regards,

Jos
Jun 5 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
3536
by: AGoTH | last post by:
class A { public: virtual void foo(int b) {} virtual void foo(char* b) {} }; class B : public A{ virtual void foo(int b) {} };
8
6741
by: Massimiliano Alberti | last post by:
Can I specialize a template function in a subclass without overriding it? (the main template function is defined in a base class). Now I'm doing something like that: (in base class) template<class X> void myfunc(X par1) { } (in derived class) template<class X>
1
2372
by: Xiangliang Meng | last post by:
Hi, all. When reading C++ books, I'm alway confused by those terms "redefining functions", "overloading functions" and "overriding functions". Please give me some comments on those terms. Thanks. If giving more strategy hehind them, more helpful. Best Regards,
15
24013
by: Susan Baker | last post by:
Hello everybody, I'm new to C++ (I have some C background). I've read up on this topic a few times but it just dosen't seem to be sinking in. 1. Whats the difference between overloading and overriding? 2. When is one preferable to use as opposed to the other? 3. How are virtual functions related to this topic (overloading/overriding) - a real world example of using virtual functions would be very much appreciated.
10
5210
by: muscha | last post by:
I don't get it. What's the main differences between overriding a base class's methods vs. hiding them? Thanks, /m
4
2225
by: Rafael Veronezi | last post by:
I have some questions about override in inheritance, and virtual members. I know that you can you override a method by two ways in C#, one, is overriding with the new keyword, like: public new bool Equals(object obj) {} Another is using the override keyword, like: public override bool Equals(object obj) {}
4
1706
by: Nilesh | last post by:
I am confused about the purpose of 'new' in overriding. Consider following example. <code_snippet> using console = System.Console; public class TestClass { public static void Main() {
17
2920
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...
1
1602
by: Tariq | last post by:
Any thoughts on how a method on a base class can be prevented from being overriden or hidden? Basically the idea is that no matter what all derived classes should use the method in my base class. Got to prevent hiding via the new keyword as well.
0
9672
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
10437
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
10001
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...
0
9042
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
6780
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
5437
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...
1
4113
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
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
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.