![]() ![]() Q3) What’s the purpose of Static methods and static variables?Īns: When there is a requirement to share a method or a variable between multiple objects of a class instead of creating separate copies for each object, we use static keyword to make a method or variable shared for all objects. The types of access specifiers for classes are:ġ) Public: Class,Method,Field is accessible from anywhere.Ģ) Protected: Method,Field can be accessed from the same class to which they belong or from the sub-classes, and from the class of same package, but not from outside.ģ) Default: Method,Field,class can be accessed only from the same package and not from outside of it’s native package.Ĥ) Private: Method,Field can be accessed from the same class to which they belong. Q2) What are the various access specifiers for Java classes?Īns: In Java, access specifiers are the keywords used before a class name which defines the access scope. □ Free PDF Download: Java Interview Interview Questions & Answers > ![]() Sub-class can access all public and protected methods and fields of its super class. An Inner class has access rights for the class which is nesting it and it can access all variables and methods defined in the outer class.Ī sub-class is a class which inherits from another class called super class. Q1) What is the difference between an Inner Class and a Sub-Class?Īns: An Inner class is a class which is nested within another class. Here are Java interview questions and answers for fresher as well as experienced candidates to get their dream job. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |