Given:
1. package test;
2.
3. class Target {
4. public String name = “hello”;
5. }
What can directly access and change the value of the
variable name?
1 any class
2 only the Target class
3 any class in the test package
4 any class that extends Target

Answers were Sorted based on User's Feedback



Given: 1. package test; 2. 3. class Target { 4. public String name = “hello”; 5. } What ca..

Answer / amit singh

first i want to see the visibility of class itis
default acees
the class is default acess so this class is visible in a
same package
so then the member in it public so
1)so the class in the same package will acess it
2)the class in the same package which extends this class
can acess it
not any other class in the whole world or subclass in other
package.
thanks amit singh
amitsing2008@gmail.com

Is This Answer Correct ?    17 Yes 0 No

Given: 1. package test; 2. 3. class Target { 4. public String name = “hello”; 5. } What ca..

Answer / ram

any class in the test package

Is This Answer Correct ?    15 Yes 6 No

Given: 1. package test; 2. 3. class Target { 4. public String name = “hello”; 5. } What ca..

Answer / manikandan [ gtec,vellore ]

Public is Visible to everywhere.
Private is visible to only the same class.
Protected is visible in same package and also sub classes in
any package.

Is This Answer Correct ?    3 Yes 0 No

Given: 1. package test; 2. 3. class Target { 4. public String name = “hello”; 5. } What ca..

Answer / r.jainrocks@gmail.com

a class which in same package
can access its variable name
no any class can access variable

1. class has default visibility so accessible in same package,
2. variable has public accessibility, can be access any class
which allowed in first condition.

Is This Answer Correct ?    1 Yes 0 No

Given: 1. package test; 2. 3. class Target { 4. public String name = “hello”; 5. } What ca..

Answer / lakshman

any class that extends Taget

Is This Answer Correct ?    6 Yes 6 No

Given: 1. package test; 2. 3. class Target { 4. public String name = “hello”; 5. } What ca..

Answer / kumar

By default,the package and class are public.the result will
be 4 any class that extends Target.

Is This Answer Correct ?    0 Yes 4 No

Given: 1. package test; 2. 3. class Target { 4. public String name = “hello”; 5. } What ca..

Answer / dilip

any class

Is This Answer Correct ?    4 Yes 9 No

Post New Answer

More Core Java Interview Questions

What is bufferedreader in java?

0 Answers  


How can a gui component handle its own events?

0 Answers  


What are event-delegation model and event-inheritance model? Which is best?

1 Answers  


1) There are 10 different threads in runnable state. Each having priority 1 to 10. How does the CPU schedules or executes these threads?

2 Answers   RBS,


Which Component subclass is used for drawing and painting?

1 Answers  






In java, how many ways you can take input from the console?

0 Answers  


what are the differences between java and .net?..why u choose java?

1 Answers  


What is the multilevel inheritance. and also give the Example of it ?

5 Answers  


What is mean by exception?

0 Answers  


State the main difference between c++ and java?

0 Answers  


What are variable names?

0 Answers  


Is simpledateformat safe to use in the multithreaded program?

0 Answers  


Categories