-4

In the following statements:

String string1 = new String("This is a string");
String string2 = new String("this is another string");

system.out.println(string1.equals(string2));

is it safe to say that the println method is dependent on the equals() method, which is dependent on the String object "string2"?

My question is not regarding the output of the code but rather whether or not the explanation of dependencies is accurate.

ThisaruG
  • 3,222
  • 7
  • 38
  • 60
Mowgli
  • 1
  • 2
  • 1
    no, it is not accurate, println does not depend on equals, it prints boolean value returned by it, but there is no dependency – Iłya Bursov Feb 17 '23 at 02:28
  • Those really aren't useful terms to explain what's going on. – Louis Wasserman Feb 17 '23 at 05:40
  • @IłyaBursov What you are saying does make sense and was my initial thought. Now I am realizing that println() does not actually require anything to be included within the parentheses and therefore it is now obvious to me it has no dependencies. – Mowgli Feb 18 '23 at 00:44
  • @Mowgli `println()` and `println(boolean)` are technically two different methods – Iłya Bursov Feb 18 '23 at 00:53
  • @IłyaBursov due to method overloading correct? – Mowgli Feb 19 '23 at 03:37

1 Answers1

-2

println does not depend on equals, it prints boolean value returned by it, but there is no dependency

Mowgli
  • 1
  • 2
  • lack of input arguments does not guarantee lack of dependencies, static method could use some global variable and thus dependent on it – Iłya Bursov Feb 19 '23 at 18:21