TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sant ku
NA
12
1.5k
object vs reference type
Nov 8 2014 9:33 PM
Consider we have follow scenario
Class base
{
public void print()
{
Console.writeline("Print from base class");
}
}
Class derived : base
{
public void print()
{
Console.writeline("Print from base class");
}
}
and in the main method if we write like this
main()
{
base b = new derived(); // My 1st question is what happens at this point in time
b.print();
} //Now then why do we need to write like this we could declared it as "base b= new base();" because anyway we can't call child class variables from b.
//also somebody pointed out that "base b = new derived();" in this case b become object of child class to a reference variable of base type.
//I want to know what does this mean.
Please suggest with your observations.
Thanks in advance
Reply
Answers (
1
)
Console take two values if needed
c sharp