JAVA Programming :: Packages

Home > Technical Aptitude > JAVA Programming > Packages > General Questions

NA
SHSTTON
1
Solv. Corr.
6
Solv. In. Corr.
7
Attempted
0 M:0 S
Avg. Time

1 / 5

Choose the correct option.

Name the access modifier which when used with a method, makes it available to all the classes in the same package and to all the subclasses of the class.


APublic

BProtected

CPrivate

DNone

Answer: Option B

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
3
Solv. Corr.
3
Solv. In. Corr.
6
Attempted
0 M:0 S
Avg. Time

2 / 5

Choose the correct option.

Which of the following are legal identifier names in Jav Select the correct answers.


A%abcd, $abcd

B$abcd, _a_long_name

C1abcd, _a_long_name

Dpackage

Answer: Option B

Explanation:

Java identifier name cannot begin with a digit.

Workspace

NA
SHSTTON
2
Solv. Corr.
4
Solv. In. Corr.
6
Attempted
0 M:0 S
Avg. Time

3 / 5

Choose the correct option.

You have a class file name Test.class inside javaproject directory.

Test.java source code is :
import javutil.Properties;
class Test {
public static void main (String[] args){
Properties p = System.getProperties();
System.out.println(p.getProperty("key1"));
}
}
you have issued below commands from command prompt.
cd javaproject
java -D key1=value1 Test
What is the output ?


Avalue1

Bnull

CRun successfully but no output

DRun fails - javlang.NoClassDefFoundError: key1=value1

Answer: Option D

Explanation:

name=value pair must follow immediately, no spaces allowed. In this case there is space between -D and key1=value1 So javlang.NoClassDefFoundError:
key1=value1.

Workspace

NA
SHSTTON
1
Solv. Corr.
4
Solv. In. Corr.
5
Attempted
0 M:0 S
Avg. Time

4 / 5

Choose the correct option.

HashMap can be synchronized by _______ ?


AMap m = Collections.synchronizeMap(hashMap);

BMap m = hashMap.synchronizeMap();

CMap m = Collection.synchronizeMap(hashMap);

DNone of the above

Answer: Option A

Explanation:

HashMap can be synchronized by Map m = Collections.synchronizeMap(hashMap);

Workspace

NA
SHSTTON
1
Solv. Corr.
4
Solv. In. Corr.
5
Attempted
0 M:0 S
Avg. Time

5 / 5

What is the output for the below code?
package bean;
public class Abc {
public static int index_val = 10;
}
package com;
import static bean.Abindex_val;
public class Test1 {
public static void main(String... args) {
System.out.println(index_val);
}
}

A10

Bcompile error, index_val not defined

CCompile error at import static bean.Abindex_val;

DNone of the above

Answer: Option A

Explanation:

The static import construct allows unqualified access to static members without inheriting from the type containing the static members. J2SE 5.0 onwards it allows static import like import static bean.Abindex_val; and can be use directly System.out.println(index_val);

Workspace