// extends method is used to get the access to the method of other class
class Counter {
int i = 0;
Counter increment() {
i++;
return this;
}
void output() {
System.out.println("Output Using Inherent method,i = " + i);
}
}
public class HackDefence extends Counter {
public static void main(String[] args) {
Counter x = new Counter();
x.increment().increment().output();
}
}
OUTPUT:
class Counter {
int i = 0;
Counter increment() {
i++;
return this;
}
void output() {
System.out.println("Output Using Inherent method,i = " + i);
}
}
public class HackDefence extends Counter {
public static void main(String[] args) {
Counter x = new Counter();
x.increment().increment().output();
}
}
OUTPUT:
No comments:
Post a Comment