Answer to Question #207247 in Java | JSP | JSF for Ema

Question #207247

Create an Alien class. Include at least three protected data members of your

choice, such as the number of eyes the Alien has. Include a constructor that

requires a value for each data field and a toString() method that returns a

String containing a complete description of the Alien. Save the file as

Alien.java.


1
Expert's answer
2021-06-15T07:08:40-0400
public class Alien
{
    protected int no_of_eyes;
    protected int no_of_legs;
    protected int no_of_heads;
    
    public Alien(int e,int l, int h){
        no_of_eyes=e;
        no_of_legs=l;
        no_of_heads=h;
    }
    public String toString(){
        System.out.println("The Alien has:\n "+no_of_eyes+" eyes\n"+no_of_legs+" legs\n"+no_of_heads+" heads\n");
        return "";
    }
	public static void main(String[] args) {
	    Alien a=new Alien(5,3,3);
	    a.toString();
	}
}

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