Advertisement
Guest User

Hide behavior of Property in Inheritance

a guest
Aug 16th, 2014
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Base class
  2. @interface BaseClass : NSObject
  3. @property(nonatomic,strong)NSString *name;
  4. @end
  5. @implementation ClassObject
  6. @synthesize name;
  7. @end
  8.  
  9. // Derived1 -class from BaseClass
  10. @interface Derived1 : BaseClass
  11. @end
  12.  
  13. @implementation classA
  14. @end
  15.  
  16. //Derived2 -class from BaseClass
  17. @interface Derived2 : BaseClass
  18. @property(nonatomic,strong)NSString *age;
  19. @end
  20. @implementation classB
  21. @synthesize age;
  22. @end
  23.  
  24. int main(int argc, char * argv[])
  25. {
  26.     @autoreleasepool {
  27.     BaseClass *instanceOfDerived1=[[Derived1 alloc]init];
  28.         BaseClass *instaceOfDerived2=[[Derived2 alloc]init];
  29.        
  30.        instanceOfDerived1.name=@"Welcome";
  31.     instanceOfDerived2.age=23// Here This property is not there in Baseclass, So Here we can't able use the Setter mechanism here for setting the Age' value, But we can able to use the Name' property.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement