class Demo
{ public static void Main()
{
System.Console.WriteLine("Demo");
OuterClass.NestedClass nc = new OuterClass.NestedClass();
}
}
class OuterClass
{
public OuterClass()
{
System.Console.WriteLine("OuterClass");
}
public class NestedClass
{
public NestedClass()
{
System.Console.WriteLine("NestedClass");
}
}
}
Output
Collapse
Demo NestedClass
The above program compiles and runs successfully to give the desired output. An attempt was made to create an object of
NestedClass. Therefore the constructor of
NestedClass got executed. There is no reason why the constructor of
OuterClass should get executed.
No comments:
Post a Comment