search
Login

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

0 votes
114 views
asked Geek 15.3k points 16 41 63

1 Answer

0 votes
class Animal {
  public Animal(String aType) {
    type = aType;
  }
  public String toString() {
    return "This is a " + type;
  }
  private String type;
}
public class MainClass {
  public static void main(String[] a) {
    Animal pet = new Animal("a");
    if (pet.getClass() == Animal.class) {
      System.out.println("it is an animal!");
    }
  }
}
answered Expert 11.4k points 14 22 28

Related questions

0 votes
2 answers 83 views
83 views
asked augustaina Sr Member 4.8k points 10 25 31
0 votes
1 answer 23 views
23 views
asked keem Expert 13.2k points 27 40 59
0 votes
1 answer 57 views
57 views
asked sara Guru 24.6k points 29 52 81
0 votes
1 answer 40 views
40 views
what is the use of object in java?
asked keem Expert 13.2k points 27 40 59
0 votes
1 answer 13 views
13 views
asked john Guru 27.1k points 31 50 97
...