Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Assign sub class object to another sub class reference.  RSS feed

 
Sandun Suranga Wijenayaka
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need a teoritical review for following error at line 20, can any one help.
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The b variable is declared as a reference variable to class type B. It can only refer to instances that IS-A B class. The c variable is declared as a reference variable to class type C. It can only refer to instances that IS-A C class. And since the compiler can confirm that there is no way to have an instance that is both IS-A B class and IS-A C class, it is a compile error.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!