Interview questions on modifier


 Interview questions on modifier



Ware access modifiers in java.?

These are the modifiers which are used to restrict the visibility of a class or a field or a method or a constructor. Java supports 4 access modifiers.

a) private : private fields or methods or constructors are visible within the class in which they are defined.

b) protected : Protected members of a class are visible within the package but they can be inherited to sub classes outside the package.

c) public : public members are visible everywhere.

d) default or No-access modifiers : Members of a class which are defined with no access modifiers are visible within the package in which they are defined.



Can a method or a class be final and abstract at the same time.?

No, it is not possible. A class or a method can not be final and abstract at the same time. final and abstract are totally opposite in nature. final class or final method must not be modified further where as abstract class or abstract method must be modified further.


Can we declare a class as private.?

We can’t declare an outer class as private. But, we can declare an inner class (class as a member of another class) as private.


 Can we declare an abstract method as private ?

No, abstract methods can not be private. They must be public or protected or default so that they can be modified further.


Can we declare a class as protected?

We can’t declare an outer class as protected. But, we can declare an inner class as protected.








Comments

Popular posts from this blog

OBJECT ORIENTED CONCEPTS

Arrays programms