Object oriented derived class

Question posted in Computer Software on 06 2010
Rate question difficulty level 0 Votes
you have this function





class A ()

{

console.write("I'm class A");

}



class B : A

{

console.write ("I'm class B");

}



void main function()

{

try{

A a = new B();

}



catch{

console.write ("Invalide code");

}

}




What would be written on the screen , or in other words is it legal to write


A a = new B();
 
 
5 Answers
 
The answer is this is Invalide code

you can not create A a = new B();
cause A doesn't know B , you can write B b= new A().

06/02/2010
 
 
Nope.
It will display "I'm class B".
The OO concept is called polymorphism.

06/02/2010
 
 
class Program
{
static void Main(string[] args)
{
Parent parent = new Child(); //ok
//Child child = new Parent(); //error
//Cannot implicitly convert type 'Parent' to 'Child'.
}
}

public class Parent {}
public class Child : Parent {}

06/21/2010
 
 
Both of you are right.
my mistake .....

Thanks.

06/21/2010
 
 
Okay I'm cnovniced. Let's put it to action.

01/01/2012
 
 
Add an answer*
 
Your name
Email
 

add a question

arrow_blue


Now hiring!
---------------------------
---------------------------
---------------------------
---------------------------
Mercer 
---------------------------
---------------------------
---------------------------