Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Abstraction

The document contains a Java program demonstrating object-oriented programming principles. It defines an abstract class 'Animals' with a constructor and methods, and two subclasses 'Horse' and 'Chicken' that implement the abstract method 'walk'. The main method creates instances of 'Horse' and 'Chicken', calling their respective 'eat' and 'walk' methods.

Uploaded by

rahulsuthrapu616
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)
7 views1 page

Abstraction

The document contains a Java program demonstrating object-oriented programming principles. It defines an abstract class 'Animals' with a constructor and methods, and two subclasses 'Horse' and 'Chicken' that implement the abstract method 'walk'. The main method creates instances of 'Horse' and 'Chicken', calling their respective 'eat' and 'walk' methods.

Uploaded by

rahulsuthrapu616
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
You are on page 1/ 1

public class OOPS_A {

public static void main(String[] args) {


Horse h=new Horse();
h.eat();
h.walk();

Chicken c=new Chicken();


c.eat();
c.walk();

}
}

abstract class Animals{


String color;
Animals(){
color="brown";
System.out.println("animals constructor called...");
}

void eat(){
System.out.println("animals eat");
}
abstract void walk();

}
class Horse extends Animals{
void walk(){
System.out.println("walks with 4 legs");
}

}
class Chicken extends Animals{
void walk(){
System.out.println("walks with 2 legs");
}
}

You might also like