using System;
using System.Collections.Generic;
using System.Text;

class BaseClass
    public virtual void method() 
    { Console.WriteLine("BaseClass method"); }

class SubClass : BaseClass
    public override void method() 
    { Console.WriteLine("SubClass method"); }
    public void someMethod() 
    { Console.WriteLine(); }
    static void Main(string[] args)
        BaseClass var = new SubClass();

The above code does not compile because var's type is BaseClass. Although var is an object of SubClass which contains the someMethod(). Could someone help. Thanks in advance.

Recommended Answers

var is a reserved word.

Jump to Post

All 2 Replies

var is a reserved word.

you cannot use keywords or special words as variables or object names.
'vsr' is a keyword for 3.5 and above versions.

try giving var1, it ll work fine.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.