Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Accessing derived class members: c# vs java

$
0
0

I understand we cannot access derived class members from base class in C#. But, in one of our other applications written in java with hibernate, I see that the application allows and does retrieve derived class members from base class. For eg.,

Classes:

public class base{ public string a{get;set;}}

public class derived:base{public string b{get;set;}}

Method

//Gets all base records

public List<base> GetAllbaseRecords()

{

}

public bool IsExist

{

   foreach(var base in GetAllbaseRecords())

   {

       string c=        base.b; //Compile error in c#

   } 

}

But, it does not throw an error and infact shows the data in java. What's the logic I'm missing here?


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>