2

Why are we allowed to assign public access specifier for a member in a private class i.e. incorrectVariable in the code below:

My code doesn't give compilation error and run properly, my code is:

private class C {
    public var incorrectVariable = "SomeString"
    var a = 5
    func fooFun() -> Int {
        self.a += 1
        return self.a
    }
}

var obj = C().a
print(obj)
obj = C().fooFun()
print(obj)
Vivek Tyagi
  • 168
  • 1
  • 4
  • 15

1 Answers1

3

If you're creating private class object with same file there is not an issue. Private class not accessible in other file.

Refer this access control for detail link

Pratik Sodha
  • 3,679
  • 2
  • 19
  • 38