Basic OOPS core java interview questions

1. What is class? 

Collection of objects, it is a structure that holds together methods, variable declaration and their definitions. We can call it as a template or blueprint of a module.

2. What is member variable?

Member variable are called fields, there are two types of member variable                         

1. Instance variable

2. Class variable

3. What is Instance variable?

Fields that are associated with object are known as instance variable, if you have an n-number of object for a class then JVM will create an n number of instance variable for you.

4. What is class variable?

Fields that are associated with class rather than object are known as class variable or static variable.

In memory there will be only one variable at all time, even though you have n-number of objects

5. What is Object?

Objects are created for class that holds a unique copy of instance variable.

All objects have state and behavior.

An object stores its state in fields (variables in some programming languages) and exposes its behavior through methods (functions in some programming languages).

6. What is method?

A method is a set of code which is referred to by name and can be called (invoked) at any point in a program simply by utilizing the method's name. 

Methods are time savers, in that they allow for the repetition of sections of code without retyping the code. 

It exposes the behavior of a class

7. Class vs. Member variable vs. Object?

                class --> StudentRegistration (template that holds a student registration form)

                object --> s1 (uniquely identifies the single student)

                instance variable --> name, mobile etc.. (Store the state of an object)

8. Four main principles of OOPS language?

1.       Abstraction

2.       Encapsulation

3.       Inheritance

4.       Polymorphism.

9. What is local variable?

Variable that is declared inside a method or any block is called as local variable.

10. Scope of instance variable?

An instance field is born when its object is created and dies when the object is garbage collected

Instance variables are always visible in all methods of the class.

Variable scope outside the class will be based on its access specifier.

11. Scope of local variable?

Local variable are visible only to its method or block where it is declared.

12. Naming standards to declare a class or interface?

Class names should be nouns.

First letter of each internal word capitalized.

Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).




13. Naming standards to declare a method or variable?

Method or variable names should be in lowercase

Multi-word names, the first letter of each of the second and following words should be capitalized

We called this naming standards and Pascal naming standards





14. Naming standards to declare constant in java?

The names of variables declared constants should be all uppercase with words separated by underscores ("_")

Example :

final int MIN_WIDTH = 4;

final int MAX_WIDTH = 999;

Related Post


         Aewewsdfbgsdf dfgsdfghdf