Welcome To The World Of Hacking


Learn Hacking|Teach Hacking|Learn To Secure|Learn To Code

Saturday

JAVA PROGRAMMING TUTORIAL 51: INHERITANCE

// 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:

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...