Question

Is there a way we can access the concrete method's of an abstract class in the direct child class as below

  abstract class ParameterBase
  {           
        public void test()
        { 
            string name = "testname";
            console.writeline(name);
        }          
  }

  public  class Parameter1 : ParameterBase 
  {
       //I Need to call(access) the Test() Method here i.e print "testname" in the  console         
  }

Now i know that we can create a instance of the child class with type as ParameterBase and access the test() method that is there in ParameterBase() as below

   ParameterBase PB = new Parameter1();
   PB.test();
Was it helpful?

Solution

You have to maintain the accessibility level while inheriting a class. You can do this :

abstract class ParameterBase
{
    public void test()
    {
        string name = "testname";
        Console.WriteLine(name);
    }
}

class Parameter1 : ParameterBase
{
    void getvalue()
    {
        Parameter1 pb = new Parameter1();
        pb.test();
    }        
}  

OTHER TIPS

Please look into this:-

class Program
{
    static void Main(string[] args)
    {
        Test2 t = new Test2();
        t.display();
        t.absDsisplay();
    }
}

abstract class Test1
{
    public void display()
    {
        Console.WriteLine("display");
    }
    public abstract void absDsisplay();

}
class Test2 : Test1
{

    void GetValu()
    {


    }

    public override void absDsisplay()
    {
        Console.WriteLine("absDisplay");
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top