Vivek Tyagi
Vivek Tyagi

Reputation: 178

Private class member accessible outside class

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)

Upvotes: 2

Views: 177

Answers (1)

Pratik Sodha
Pratik Sodha

Reputation: 3727

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

Upvotes: 3

Related Questions