Answer to Question #239264 in Java | JSP | JSF for zakia kafeel

Question #239264

Write a program with a mother class animal. Inside it define a name and an age variables, and

set_value() method.Then create two instance variables Zebra and Dolphin which write a message

telling the age, the name and giving some extra information (e.g. place of origin).


1
Expert's answer
2021-09-22T00:05:18-0400
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package animal;




public class Animal {


    protected String name;
protected int  age;


public void setAnimals(String n, int a){
    name = n;
    age = a;
}
    public static void main(String[] args) {
       Zebra z = new Zebra();
       Dolphin dolp = new Dolphin();
       z.setAnimals("Ana", 5);
       dolp.setAnimals("Jin", 2);
       z.message_zebra();
       dolp.message_dolphin();
    }
    
}
class Zebra extends Animal{
    public void message_zebra()
{
    System.out.printf("The zebra named  %s is %d years old.  The zebra comes from Africa. \n", name, age) ;
}


}


class Dolphin extends Animal{
    public void message_dolphin()
{
    System.out.printf("The dolphin named  %s is %d years old.  The dolphincomes from Africa. \n", name, age) ;
}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS