Menu
Topics Index
...
`

Print Writer


If you need explanation Read this topic

If you need Answer Take test on this topic

Print Writer
What will be the output of the following program?
import java.io.*;
public class CheckError {
    public static void main(String args[]) {
        String str = "Error or Not";
        PrintWriter pw = new PrintWriter(System.out);
        pw.append(str);
        PrintWriter py = new PrintWriter(System.out);
        py.append("Error or Not");
        System.out.println(pw.equals(py));
    }
}

A. true
B. false
C. Error or Nottrue
D. Error or Notfalse
E. Compilation Error or Runtime Error
Topic: PrintWriter Class In Java

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.

answer is B
False

here the above example here we are taking a string variable with data in it as  "Error or Not" is assigned to varaible named str

and we are creating a PrintWriter class object and we are appending the s variable string data to the pw object reference
here in second PrintWriter class object and we are appending the data directly to it and then after comparing them both it compares the hashcodes init which is not same so it prints the false

Posted by Vicky Maduri    2015-02-19 16:10:18


ans is (B) because in pw variable we are appending with variable and in py we are directly appending the string using system.out....

Posted by Anuj Batham    2015-02-19 16:19:48


n

Posted by Shubham Bansal    2015-02-19 19:17:35


This dose is now closed and the winners are Vicky Maduri,  for 'First Correct Comment', Sai Ram,  for 'Best Comment' and Sai Ram for the 'Popular Comment'. The 'lucky liker' is ?????????? ?????. 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    2015-02-20 05:08:17


© meritcampus 2019

All Rights Reserved.

Open In App