Console class in Java

0
114

In this article we will learn about Console class in Java.

In JDK 1.5 a new class was introduced under IO package i.e. Console class which is a concrete class. Although Console class is a concrete class we can’t create object of this class but we can retrieve the reference of console object by using System.Console.

Since Console class has a private constructor that is why we are unable to create an object to Console class.

 

Let us take a look at the below program:

 

[java]

public class Manager{

public static void main(String[] args){

System.out.println(1);

Console c1=System.console();

System.out.println(c1);

System.out.println(2);

Console c2=System.console();

System.out.println(c1==c2);

}

}

[/java]

 

OUTPUT:

1

null

2

true

Facebook Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.