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
88 views
asked Geek 15.3k points 16 41 63

1 Answer

0 votes
class MyClass {
  int height;

  MyClass() {
    System.out.println("Planting a seedling");
    height = 0;
  }

  MyClass(int i) {
    System.out.println("Creating new Tree that is " + i + " feet tall");
    height = i;
  }

  void info() {
    System.out.println("Tree is " + height + " feet tall");
  }

  void info(String s) {
    System.out.println(s + ": Tree is " + height + " feet tall");
  }
}

public class MainClass {
  public static void main(String[] args) {
    MyClass t = new MyClass(0);
    t.info();
    t.info("overloaded method");
    // Overloaded constructor:
    new MyClass();
  }
}
output
Creating new Tree that is 0 feet tall
Tree is 0 feet tall
overloaded method: Tree is 0 feet tall
Planting a seedling
answered Expert 11.4k points 14 22 28

Related questions

0 votes
1 answer 40 views
40 views
asked smith Geek 15.3k points 16 41 63
0 votes
1 answer 89 views
89 views
asked augustaina Sr Member 4.8k points 10 25 31
0 votes
1 answer 82 views
82 views
asked augustaina Sr Member 4.8k points 10 25 31
0 votes
1 answer 107 views
0 votes
1 answer 1.4K views
1.4K views
asked felin Advisor 8.4k points 10 15 18
...