Home > database >  A title
A title

Time:09-15

Suppose you have an Animal Animal are defined as follows:

The class Animal {

Public String name;

public int age;

Public Animal (String name, int age) {

This. Name=name;

Enclosing the age=age;

}

Public void introduce () {

System. The out. Println (" My name is "+ name +", My age is "+ age);

}

Public void sleep () {

System. Out.println (name + "is sleeping now!" );

}

}

When the instantiation Animal, if age age<0, throws an AgeException abnormalities, try to create this exception class, and rewrite the above Animal class constructor, make it throws a AgeException abnormalities, in addition to write the code from the keyboard input data, create two instance objects, verify this exception, for example, the program runs according to the following:

My name is Tom, My age is 2

Jerry is younger than zero.



CodePudding user response:

There are specializing in, let the webmaster help you move to Java edition piece,
  • Related