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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

why using interface interface ?

1785


Can you run java program without main method?

808


What is the method in java?

848


Can extern variables be initialized?

695


Explain the difference between abstraction and encapsulation.

753


What do you understand by Header linked List?

834


How do you remove an element from an arraylist in java?

689


Why is string buffer better than string ?

811


What are the advantages of encapsulation in java?

768


Can we use a switch statement with strings?

782


Why generics are used in java?

792


Does java allow overriding static methods ?

847


What is the order of arraylist in java?

844


What is prefix of a string?

810


Is c better than java?

745