Developer community
0 votes
86 views
asked by Geek (15.3k points) 15 40 60 | 86 views

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 by Expert (11.4k points) 14 22 29

Related questions

0 votes
1 answer
asked by smith Geek (15.3k points) 15 40 60 | 36 views
0 votes
1 answer
asked by augustaina Sr Member (4.8k points) 10 23 31 | 88 views
0 votes
1 answer
asked by augustaina Sr Member (4.8k points) 10 23 31 | 80 views
0 votes
1 answer
asked by smith Geek (15.3k points) 15 40 60 | 105 views
0 votes
1 answer
asked by felin Advisor (8.4k points) 10 15 18 | 1.4k views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


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

3.8k questions

4k answers

117 comments

10.7k users

3,751 questions
4,046 answers
117 comments
10,709 users