I tried this Swift code in XCode.
File1.swift(Non-Main File):
class A {
fileprivate func myFun() {
print("A myFun")
}
}
class B: A {
override internal func myFun() {
super.myFun()
print("B myFun")
}
}
To note:
- 'A' does not provide access to 'myFun' to an object made outside of File1.
- 'B' subclasses A and overrides 'myFun' with an internal access specifier.
main.swift
let s = B()
s.myFun()
Output:
A myFun
B myFun
Program ended with exit code: 0
To note:
- I used a subclass(B) to access a part of the superclass(A) which it didn't allow to be accessed.
Is this behavior intended? If yes then how is this useful?