Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Basics Perfecting the Prototype Censoring Words - Using String Equality

Aditya Puri
Aditya Puri
1,080 Points

How is "System" a object?

At 0:31 Craig says- "We have already seen how methods can be called on objects like System, console etc.."

Now I understand that "console" is an object, it is an instance of the class Console.

But how is "System" an object? We use the static method "exit" on the class "System" itself without making an instance of the class. Then why does he call "System" an object? Shouldn't it be a class??

3 Answers

Marina Alenskaja
Marina Alenskaja
9,320 Points

"The System class contains several useful class fields and methods. It cannot be instantiated." - https://docs.oracle.com/javase/7/docs/api/java/lang/System.html

Aditya Puri
Aditya Puri
1,080 Points

So the "System" class is both an object and a class? As we cannot create its instances??

Alexander Nikiforov
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 Points

System is a Class but as every Class in Java inherits java.lang.Object.

So System is a Class and if you go to definition of Systemthere is invisible line ... class System extends Object

And no System class cannot be instantiated, because, see here:

http://stackoverflow.com/questions/12392888/why-system-class-cannot-be-instantiated

From answers there: It cannot be instantiated because "it has a private constructor" and "only is a bunch of static methods and properties."