Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,948 questions

51,890 answers

573 users

How to implement interface in Java

1 Answer

0 votes
package javaapplication1;

public interface Animal {
 
    public void Showtalent(String talent);
    public void showDetails();
}
package javaapplication1;

public class Dog implements Animal {
    public void Showtalent(String talent) {
        System.out.println("talent: " + talent);
    }
     
    public void showDetails() {
        System.out.println("I'm a dog");
    }
}
package javaapplication1;

public class Bird implements Animal {
    public void Showtalent(String talent) {
        System.out.println("talent: " + talent);
    }
     
    public void showDetails() {
        System.out.println("I'm a bird");
    }
}
package javaapplication1;

public class InterfaceTest {
    public static void main(String[] args) {
	    Animal dog = new Dog();
	    Animal bird = new Bird();
 
	    dog.showDetails();
	    dog.Showtalent("can run");
        
        bird.showDetails();
        bird.Showtalent("can fly");
    }
}

/*
run:

I'm a dog
talent: can run
I'm a bird
talent: can fly

*/

 



answered Jan 7, 2016 by avibootz

Related questions

1 answer 145 views
1 answer 139 views
139 views asked Apr 27, 2017 by avibootz
1 answer 155 views
2 answers 196 views
196 views asked Jan 17, 2016 by avibootz
...