what does '()' denote in the object creation statement?
It denotes the constructor.
what does '()' denote in the object creation statement
How to call a base class constructor from a derived class?
How to call a base class constructor from a derived class?
using System;
using System.Collections.Generic;
using System.Text;
namespace OOPTest7
{
class A
{
public A()
{
Console.Out.Write("base A");
}
public A(string s)
{
Console.Out.Write(s);
}
}
class B : A
{
public B() : base("base cons called from Derived")
{
Console.Out.Write("B");
}
}
class Program
{
static void Main(string[] args)
{
B b= new B();
Console.In.Read();
}
}
}
interface ,the class which implemented it and its object, with interface in left hand side during creation
If a class IA is implementing an interface I which is having a method a, then
can is the following allowed? Will that have all the methods of IA apart from that of interface I?
I a = new IA();
Yes. always the base class or interface can contain derived class, but it will have
only those of the base. So it will not have members of IA which are not from interface I.
using System;
using System.Collections.Generic;
using System.Text;
namespace OOPTest6
{
interface I
{
void a();
}
class IA : I
{
public void a()
{
Console.Out.Write("a");
}
public void nonintfacemeth()
{
Console.Out.Write("nonintfacemeth");
}
}
class Program
{
static void Main(string[] args)
{
I i = new IA();
i.a();
}
}
}
If A is the base class and B inherits B and C inherits B and an object is created for C , whats order of constructor
If A is the base class and B inherits B and C inherits B and an object is created for C , then what will be the order of
the constructor being called?
A then B then C.
using System;
using System.Collections.Generic;
using System.Text;
namespace OopTest5
{
class A
{
public A()
{
Console.Out.Write("A");
}
}
class B : A
{
public B()
{
Console.Out.Write("B");
}
}
class C : B
{
public C()
{
Console.Out.Write("C");
}
}
class Program
{
static void Main(string[] args)
{
C c = new C();
Console.In.Read();
}
}
}
how to implement a pure virtual function in c#?
how to implement a pure virtual function in c#?
using System;
using System.Collections.Generic;
using System.Text;
namespace OppTest4
{
abstract class abTest
{
public abstract void a();
}
class UsesabTest : abTest
{
public override void a()
{
Console.Out.Write("a");
}
public void x()
{
Console.Out.Write("x");
}
}
class Program
{
static void Main(string[] args)
{
UsesabTest mn = new UsesabTest();
mn.a();
}
}
}
Does C# (.NET) support partial implementation?
Does C# (.NET) support partial implementation?
No.
the following program will throw an error.
using System;
using System.Collections.Generic;
using System.Text;
namespace OPPTest3
{
interface IA
{
void x();
void y();
}
class IAClass : IA
{
public void x()
{
Console.Out.Write("test x");
}
}
class Program
{
static void Main(string[] args)
{
IAClass m = new IAClass();
m.x();
m.y();
}
}
}
Does C# (.NET) support partial implementation?
Does C# (.NET) support partial implementation?
No.
the following program will throw an error.
using System;
using System.Collections.Generic;
using System.Text;
namespace OPPTest3
{
interface IA
{
void x();
void y();
}
class IAClass : IA
{
public void x()
{
Console.Out.Write("test x");
}
}
class Program
{
static void Main(string[] args)
{
IAClass m = new IAClass();
m.x();
m.y();
}
}
}
Can we leave a virtual function in an abstract class without implementing in the derived class
Does c# support pure virtual function?
No.
Instead you can use abstract function which is also called as a pure virtual function.
abstract class abTest
{
public abstract void a();
}
Can we leave a virtual function in an abstract class without implementing in the derived class ?
No. It will throw an error.
using System;
using System.Collections.Generic;
using System.Text;
namespace OppTest4
{
abstract class abTest
{
public abstract void a();
}
class UsesabTest : abTest
{
//public override void a()
//{
// Console.Out.Write("a");
//}
public void x()
{
Console.Out.Write("x");
}
}
class Program
{
static void Main(string[] args)
{
}
}
}
Class implementing Interface
using System;
using System.Collections.Generic;
using System.Text;
namespace OppTest2
{
interface IA
{
void x();
void y();
}
class IAClass : IA
{
public void x()
{
Console.Out.Write("test x");
}
public void y()
{
Console.Out.Write("test y");
}
}
class Program
{
static void Main(string[] args)
{
IAClass m = new IAClass();
m.x();
m.y();
}
}
}