473,701 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can you please help me with Abstract and Interface...

19 New Member
Can you please help me with my assignment.I coded it and it runs I just need someone to help me a bit.
The behaviour of monekys and human beings are Similar (Breeding and breathing are Identical and walking ,communication and eatng are common but non-identical)here is my code:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  5. namespace Project1
  6. {
  7.     public abstract class abstractAnimalsComonBehaviour:Animals
  8.     {
  9.         public abstract void breeding();
  10.         public abstract void breathing();
  11.         public abstract void walking();
  12.         public abstract void eating();
  13.         public abstract void communicating();
  18.     }
  19. }
  22. using System;
  23. using System.Collections.Generic;
  24. using System.Text;
  26. namespace Project1
  27. {
  28.     public interface Animals
  29.     {
  30.       void breathing();
  31.       void breeding();
  32.       void walking();
  33.       void communicating();
  34.       void eating();
  35.     }
  36. }
  39. using System;
  40. using System.Collections.Generic;
  41. using System.Text;
  43. namespace Project1
  44. {
  45.     class HumanBeings:abstractAnimalsComonBehaviour
  46.     {
  47.         public override  void walking()
  48.         {
  49.             Console.WriteLine("walking");
  50.         }
  51.         public override  void eating()
  52.         {
  53.             Console.WriteLine("fork and knife");
  54.         }
  55.         public override  void communicating()
  56.         {
  57.             Console.WriteLine("talking");
  58.         }
  59.         public override void breeding()
  60.         {
  61.             Console.WriteLine("Breed");
  62.         }
  63.         public override void breathing()
  64.         {
  65.             Console.WriteLine("Breath");
  66.         }
  68.     }
  69. }
  72. using System;
  73. using System.Collections.Generic;
  74. using System.Text;
  76. namespace Project1
  77. {
  78.     class Monkey : abstractAnimalsComonBehaviour
  79.     {
  80.         public override void walking()
  81.         {
  82.             Console.WriteLine("Jumping");
  83.         }
  84.         public override  void eating()
  85.         {
  86.             Console.WriteLine("using hands");
  87.         }
  88.         public override  void communicating()
  89.         {
  90.             Console.WriteLine("scream");
  91.         }
  92.         public override void breeding()
  93.         {
  94.             Console.WriteLine("Breed");
  95.         }
  96.         public override void breathing()
  97.         {
  98.             Console.WriteLine("Breath");
  99.         }
  102.     }
  103. }
  107. using System;
  108. using System.Collections.Generic;
  109. using System.Text;
  111. namespace Project1
  112. {
  113.     class Program
  114.     {
  115.         static void Main(string[] args)
  116.         {
  117.             Animals Bobo = new Monkey();
  118.             Bobo.eating();
  119.             Bobo.breathing();
  120.             Animals John = new HumanBeings();
  121.             John.eating();
  122.             John.breeding();
  123.         }
  124.     }
  125. }
as you can see breething and breeding have the same output when their method is called.Is there any way not to re-type the breed and breath in one of the HumanBeings or Moneky???Can you please provide me the code for that?
Apr 10 '09 #1
2 1391
344 Contributor
I think a base class for both Monkey and HumanBeings that implement the details of the common methods and declare the others as virtual.
Apr 14 '09 #2
750 Recognized Expert Contributor
Look into How to Override, Abstact class inheritance Abstract vs interface
Apr 14 '09 #3

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

Similar topics

by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
by: Brett | last post by:
I'm still trying to figure out concrete reasons to use one over the other. I understand the abstract class can have implementation in its methods and derived classes can only inherit one abstract class. The interface has implied abstract methods/properties and derived classes can inherit multiple interfaces. The interface properties/methods have no implementation. Besides definitions of the two, what are some conceptual reasons to use...
by: Joe | last post by:
My question is more an OOD question. I know *how* to implement both abstract classes and interfaces. Here's my question - under what circumstacnes does one use an abstract class and under what circumstacnes does one implement an interface? TIA, -- Joe VBA Automation/VB/C++/Web and DB development
by: Sean Kirkpatrick | last post by:
To my eye, there doesn't seem to be a whole lot of difference between the two of them from a functional point of view. Can someone give me a good explanation of why one vs the other? Sean
by: Tony Johansson | last post by:
Hello!! Assume you have an Interface called ITest with these three method declarations. interface ITest { void foo1(); void foo2(); void foo3(); }
by: David Zha0 | last post by:
Hi, "when we call a virtual method, the runtime will check the instance who called the method and then choose the suitable override method, this may causes the performance drop down", is this right? And, why not use "new" instead of using "virtual"? And the last question, what is the differences between a abstract method and a interface?
by: Ben Voigt [C++ MVP] | last post by:
I get C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member 'UselessJunkForDissassembly.IInvocableInternals.OperationValidate(string)' C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member...
by: Miguel Guedes | last post by:
Hello, I recently read an interview with Bjarne Stroustrup in which he says that pure abstract classes should *not* contain any data. However, I have found that at times situations are when it would be useful to have /some/ data defined in such an abstract class for reasons of forming a common block of data existing in or used by all descendant classes (see example below.) In such a case where a common block of data *always* exists,...
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, I am actually a VB.Net guy, but I have worked somewhat with C++ and C#. I just want to ask about the relationship between Abstract Classes and Interfaces. My first question is if C# even has Iinterfaces. I took some Java programming classes and Interfaces are a main staple of Java. And in VB.Net I use interfaces for setting up definitions of classes. I am guessing that Abstract classes in C# do the same thing as...
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...
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: 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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.