About Question com.enthuware.ets.scjp.v6.2.325 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
kantharos
Posts: 1
Joined: Mon Feb 17, 2014 5:56 pm
Contact:

About Question com.enthuware.ets.scjp.v6.2.325 :

Post by kantharos »

//In File Test.java
package testPackage;
import other.*;
class Test
{
public static void main(String[] args)
{
// ...
}
}
class Other { static String hello = "Hello"; }

What will be the output of running class Test?

IMO NOTHING, because it won't run, as class Test is not public.

admin
Site Admin
Posts: 10385
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.325 :

Post by admin »

The main method has to be public. There is no restriction on the class.

piotrkmiotczyk
Posts: 27
Joined: Mon Sep 22, 2014 1:30 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.325 :

Post by piotrkmiotczyk »

These are the six facts on Strings:
1. Literal strings within the same class in the same package represent references to the same String object.
2. Literal strings within different classes in the same package represent references to the same String object.
3. Literal strings within different classes in different packages likewise represent references to the same String object.

How does it relate to an explanation earlier suggesting that interning pool can get GC'd with an object/class? Are they stored per-object, per-class or globally? If globally, as suggested above, I don't see a way for objects in the pool to get GC'd.

admin
Site Admin
Posts: 10385
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.325 :

Post by admin »

I am sorry but I did not understand your question. interned Strings are not GCed and literal strings are interned. So I am not sure what is the issue.

unranked
Posts: 3
Joined: Thu Jan 14, 2021 9:57 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.325 :

Post by unranked »

package other;
public class Other { public static String hello = "Hello";}

package testPackage;
public class Test {
public static void main(String[] args) {
System.out.println(testPackage.Other.hello == hello); // line 1
}
}

but there's no Other class in testPackage. It must not compile

admin
Site Admin
Posts: 10385
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.325 :

Post by admin »

Scroll down. The last line of the code snippet declares class Other.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests