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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is abstract class? Explain

597


What are latest features introduced with java 8?

593


What is floor in java?

560


What are the escape sequences in java?

565


What are the differences between the constructors and methods?

579






What are register variables what are the advantages?

450


How do you test a method for an exception using junit?

535


Can a constructor be private and how are this() and super() method used with constructor?

529


Why heap memory is called heap?

588


How hashmap works in java?

570


What are 3 boolean operators?

535


How do you define a set in java?

513


What are the elements of java?

563


Does a class inherit the constructors of its superclass in java programming?

529


What is token in java?

533