Thread: Quiz Time
View Single Post
  #114 (permalink)  
Old 05-09-2008, 04:00 PM
sanjeevtarar's Avatar
sanjeevtarar sanjeevtarar is offline
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
Quote:
Originally Posted by rjuyal View Post
Thts Right Sanjeev,

What's the answer of this:-

package com.faaltu.Quiz;

one more

Code:
public class StringInternTest { public static void main(String[] args) { String str1 = "string"; String str2 = new String("string").intern(); String str3 = new String("string").intern(); if ( str1 == str2){ System.out.println("\nSAME"); }else{ System.out.println("\nNEAH"); } if ( str1 == str3){ System.out.println("\nSAME"); }else{ System.out.println("\nNEAH"); } if ( str2 == str3){ System.out.println("\nSAME"); }else{ System.out.println("\nNEAH"); } } }
SAME

SAME

SAME

because you are using intern()........which causes new String object to point existing one if any exist.
__________________
sanjeev,संजीव
Reply With Quote