Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

confusion in S.o.p  RSS feed

 
sachin yadav
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

I know that in System.out.println, System is the class, out is the object connected to output consol and println is a method. so how is it possible to call a method using

"class(System).object(out).method(println)".

can't we do it by simply using

"object(out).method(println)"

which is the default way to call methods of a class.

bye,
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
out.println("this would be ambiguous -- which out?");
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println("Hello World");

System is a class (in the package java.lang).

out is a public static member variable of class System. The type of the variable is PrintStream.

public void println(String x) is a method of class PrintStream.

If you want you could do something like this:
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!