473,387 Members | 1,691 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,387 software developers and data experts.

marked as override cannot be marked as new or virtual

Hello,
i have do do an exercise,
but i have always an error like"marked as override cannot be marked as new or virtual"
my program is:



Expand|Select|Wrap|Line Numbers
  1. public class Shape
  2.  
  3. {
  4.     protected Point p;
  5.     public Point my_p
  6.     {get; set;}
  7.     public Shape (){}
  8.     public Shape(Point p) { this.p = new Point(p.my_x, p.my_y); }
  9.     public virtual void Show() { p.Show(); }
  10. }
  11.  
  12.  
  13. public class Segment :Shape
  14. {
  15.  
  16.    protected int a;
  17.  
  18.    public int my_a { get; set; }
  19.    public Segment() :base(new Point(0,0))
  20.    {this.a = 0; }
  21.  
  22.     public Segment(Point p, int a):base(p)
  23.     { this.a = a; }
  24.     public override void Show()
  25.     {
  26.         Console.WriteLine("Segment Point ");
  27.         p.Show();
  28.         Console.WriteLine("Length ",a);
  29.  
  30.     }
  31. }
  32.  
  33.  
  34.  
  35. public class RealPoint : Segment
  36. {
  37.  
  38.  
  39.     public RealPoint(Point p)
  40.         : base(p, 0) {}
  41.     public  override void Show()
  42.  { Console.WriteLine("RealPoint Point "); p.Show();}
  43.  
  44. }
  45.  
  46.  
  47.  
  48.  
  49. using System;
  50.    public class Point
  51.     {
  52.       public int x;
  53.   public int y;
  54.     public Point() { x = 0; y = 0; }
  55.     public Point(int x,int y) { this.x = x; this.y = y; }
  56.     public Point(Point p) { this.x = p.my_x; this.y = p.my_y; }
  57.  
  58.     public int my_x { get { return x; } set {  x = value; } }
  59.     public int my_y { get { return y; } set {  y = value; } }
  60.         public static Point operator +(Point p1, Point p2)
  61.         {
  62.             Point ret = new Point(p1.x + p2.x, p1.y + p2.y);
  63.             return ret;
  64.         }
  65.         public static Point operator -(Point p1, Point p2)
  66.         {
  67.             Point ret = new Point(p1.x - p2.x, p1.y - p2.y);
  68.             return ret;
  69.  
  70.         }
  71.         public static Point operator +(Point p1, Size s)
  72.         {
  73.             Point ret = new Point(  p1.x + (int)s.my_x,p1.y + (int)s.my_y);
  74.  
  75.  
  76.             return ret;
  77.  
  78.         }
  79.  
  80.         public void Show(){
  81.  
  82.            Console.WriteLine("(",x,",",y,")");
  83.  
  84.        }
  85.  
  86.     }
  87.  
  88.  
  89.  
  90.  
  91. public class Size
  92. {
  93.     public uint x;
  94.     public uint y;
  95.     public Size() { x = 0; y = 0; }
  96.     public Size(uint x,uint y) {this.x = x; this.y = y; }
  97.     public uint my_x { get { return x; } set { if (value >= 0) x = value; } }
  98.     public uint my_y { get { return y; } set { if (value >= 0) y = value; } }
  99.      public static Size operator +(Size s, Point p1)
  100.     {
  101.      Size ret = new Size();
  102.         return ret;
  103.  
  104.      }
  105.  
  106.          public void Show()
  107.         {
  108.  
  109.             Console.WriteLine("(", x, ",", y, ")");
  110.  
  111.         }
  112. }

I have blue marks in the show function with the above error (marked as override cannot be marked as new or virtual)

thank for asnwer
Apr 12 '13 #1
0 1104

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

Similar topics

32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
5
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int...
9
by: Ken Varn | last post by:
Is there anyway to override a public virtual method or property so that it is private in my derived class? I tried using new on the property and making it private, but no luck. --...
3
by: A.Bekiaris | last post by:
Hi I have an abstract class with some virtual methods which I inherit and create say Class1 I want to give end users the ability to override the virtual methods of the base class How this can...
1
by: Stephane | last post by:
Hi, I'm trying to create a virtual directory dynamically in my web site using ASP.NET. I received this error: System.Runtime.InteropServices.COMException (0x800700B7): Cannot create a file...
4
by: moleskyca1 | last post by:
What operators cannot be virtual and why? I looked at FAQ and found nothing. I think there are operators that cannot be virtual, but I don't know why?
1
by: bullibabu | last post by:
Dear members, I have a question. why the constructor cannot be virtual and friend? Could someone clarify me with explanation. Thanks Srinivas
1
by: muler | last post by:
"If an instance method declaration includes the sealed modifier, it must also include the override modifier." The C# Programming Language, § 10.5.5 Sealed Methods Why is this? Thanks,...
4
by: rajeev2007 | last post by:
why we cannot create virtual constructor.
8
by: puzzlecracker | last post by:
The statement is taken from FAQ . What about non-virtual functions? Can they be overriden? I still don't see a good justification to prefer private inheritance over composition. In fact, I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.