• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

this a scjp question a friend mail to me need help?

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.*;
public class OutOut
{
public static void main(String args[]) throws IOException
{
PrintStream pr = new PrintStream(new FileOutputStream("outfile"));
System.out = pr;
System.out.println("Lets see what I see now??");
}
}
1. The code causes a compiler error. out is a declared final in
System and cannot be assigned to pr.
2. The code causes a runtime Exception due the assignment to a
final variable.
3. The code compiles and runs success fully. A file
called "outfile" is created and "Lets see what I see now??"
is printed in the same.
the Given ans:1
in my option :2
I can distinct the diference from ans1 and ans2.Somebody kind enough to clearfy me?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler can determine which variables are final, that is not a runtime function.
Bill
 
This looks like a job for .... legal tender! It says so right in this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic