Win a copy of Rust Web Development this week in the Other Languages forum!

Harihar Eswaran

+ Follow
since Oct 09, 2000
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Harihar Eswaran

Thats a Wonderful answer given by Stephanie.

Originally posted by Stephanie Grasson:
The difference is as follows:
String = "abc";
creates a String [b]literal
, which goes into the String pool.
String = new String("abc");
create a new String object.
If you have many String literals with the same value, they only get put in the String pool once. For example:
String s1 = "abc";
String s2 = "abc";
String s3 = "abc";
Only one String literal is created in the String pool. s1, s2 and s3 all refer to the same String literal. Hence,
s1 == s2 is true.
s2 == s3 is true.
s3 == s1 is true.
On the other hand,
String s1 = new String("abc");
String s2 = new String("abc");
String s3 = new String("abc");
Three unique String objects are created by the lines above. Hence,
s1 == s2 is false;
s2 == s3 is false;
s3 == s1 is false;
Hope this helps.
[This message has been edited by Stephanie Grasson (edited September 28, 2000).][/B]

21 years ago
Hi Jayashree,
The keyword public means that the variable (level4) of type Sting is made visible or can be accessed anywhere outside the scope of the class AccessWidget and
the variable level2 is accessible only within the scope of the class AccessWidget as it is a static reference.
Hope this answers your question.

Originally posted by Jayashree Varahan:
public class AccessWidget
String level2 = "Test1" ;
public String level4 = "Test2" ;
What is the difference between these 2 variables? What is the scope of the first variable "level2" and what is the scope of the second variable "level4". What is the default scope of a data memeber and a class?

21 years ago