0% found this document useful (0 votes)
2 views1 page

Abstract Interface

The document presents two programming concepts: an abstract class and an interface in Java, both defining a method 'sound' for animals. In both cases, the 'Dog' class implements the 'sound' method to output 'Woof'. The examples demonstrate how to create instances of the 'Dog' class and invoke the 'sound' method, producing the same output in both scenarios.

Uploaded by

lenadeva2025
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Abstract Interface

The document presents two programming concepts: an abstract class and an interface in Java, both defining a method 'sound' for animals. In both cases, the 'Dog' class implements the 'sound' method to output 'Woof'. The examples demonstrate how to create instances of the 'Dog' class and invoke the 'sound' method, producing the same output in both scenarios.

Uploaded by

lenadeva2025
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Abstract Class

abstract class Animal


{
public abstract void sound();
}

public class Dog extends Animal


{
public void sound(){
[Link]("Woof");
}

public static void main(String args[])


{
Dog d = new Dog();
[Link]();
}
}
Output:

Woof

Interface
// Interface defines
interface Animal {
void sound();
}

// Dog implements
class Dog implements Animal { // Use 'implements'

public void sound() {


[Link]("Woof");
}

public static void main(String args[]) {


Dog d = new Dog();
[Link]();
}
}
Output:

Woof

You might also like