Menu
Topics Index
...
`

PrintStreamExample


If you need explanation Read this topic

If you need Answer Take test on this topic

PrintStreamExample
What will be the output of the following program?
import java.io.*;
public class PrintStreamExample {
    public static void main(String[] args) {
        char c = 'S';
        PrintStream ps = new PrintStream(System.out);
        ps.append(c);
        ps.append('u');
        ps.append('n');
    }
}

A. (EMPTY)
B. Sun
C. Compilation Error
D. Runtime Error
Topic: Java PrintStream Class

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

B

Posted by Chandra Sekhar Reddy    2014-11-21 04:00:27


ans is B... System class has a out object of PrintStream class.. so its can call same operation which is done by SOP

Posted by Raju VarshnEy    2014-11-21 04:02:22


Answer is b...printstream is a sub type of outputstream class ...syste.out is console. ..append method appends the subsequence of characters to the printstream which is console

Posted by Shashanka Mogaliraju    2014-11-21 04:11:05


Ans is B..A PrintStream adds functionality to another output stream, namely the ability to print representations of various data values conveniently..

in PrintStream flush() automatically invoked once we complete the writting....we have many methods in the PS clsas like println(),format(),print(),flush() etc...

characters printed by a PrintStream are converted into bytes using the platform's default character encoding

here we create the PrintStream instance by passing the System.out as Arg...here suitable constructor will get invoked and the  new PrintStream will get created..

next here we create char variable and assigned with char 'c'...

here we are calling the append() by passing the chars to it...this method will append the specified char to the OutputStream...

Posted by Uday Kumar    2014-11-21 13:35:42


A

Posted by Dereje Goshu    2014-11-21 16:28:36


a

Posted by Shubham Bansal    2014-11-21 18:21:39


ans b.The PrintStream class provides support for writing string representations of primitive data types and
objects to an underlying output stream                                                                      A PrintStream object is often used to write to a BufferedOutputStream object. Note that you
can specify that the PrintStream be flushed every time it writes the line separator or the newline
character by using the constructor that takes a boolean argument.  .                                                    System is a class. It has a class variable named out. out refers to an object of type
PrintStream. The object System.out has an instance method named println().The
System.out and System.err streams are PrintStream objects;the PrintStream class has been enhanced to translate characters to bytes using the system's default encoding
scheme.                                                                                                                       Unlike methods in other stream classes, the methods of PrintWriter and PrintStream do not throw IOExceptions.                                                               If we can't parse the request or the file
doesn't exist, we wrap our OutputStream with a PrintStream to make it easier to send a textual
message.All of the methods of PrintStream that write multiple times to the underlying output stream handle
synchronization internally, so that PrintStream objects are thread-safe.                               The StringBuffer class actually provides a number of overloaded append() methods, for appending various
types of data to the buffer.                                                                                          coming to this program char c is assigned with 'S'   ,objct for printstream created.by using appen() we can add char to string buffer.finally all the char displayed togethr lik string "Sun"

Posted by Maheshwari Natarajan    2014-11-21 18:47:36


This dose is now closed and the winners are Sai Ram,  for 'First Correct Comment', Uday Kumar, Maheshwari Natarajan,  for 'Best Comment' and Sai Ram for the 'Popular Comment'. The 'lucky liker' is Bolo Raven. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-11-23 02:04:29


© meritcampus 2019

All Rights Reserved.

Open In App