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

Question #239267

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-20T11:08:59-0400

Animal.java

public class Animal {
    private String name;
    private int age;

    void set_value(String name, int age) {
        this.name = name;
        this.age = age;
    }

    String get_name() {
        return name;
    }

    int get_age() {
        return age;
    }
}

Main.java

public class Main {
    private static Animal zebra = new Animal();
    private static Animal dolphin = new Animal();

    public static void main(String[] args) {
        zebra.set_value("Zebra", 18);
        System.out.println("Name: " + zebra.get_name());
        System.out.println("Age: " + zebra.get_age());
        System.out.println("Place of origin: Africa");

        System.out.println("");
        
        dolphin.set_value("Dolphin", 15);
        System.out.println("Name: " + dolphin.get_name());
        System.out.println("Age: " + dolphin.get_age());
        System.out.println("Place of origin: Ocean");
    }
}

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