Shrikiran11 / Js_css_Bootstrap

0 stars 0 forks source link

private constructor #3

Open Shrikiran11 opened 2 years ago

Shrikiran11 commented 2 years ago

class Zoo { int animalCount;

Zoo() {

}

private Zoo(int an) {
    animalCount = an;
}

}

class ZooKeeper { public static void main(String[] args) { Zoo z = new Zoo(92); System.out.println(z.animalCount); } } //compile time error //Zoo(int) has private access in Zoo