1.What are the oops concepts in java?

basic oops concepts in java

 




2. What is encapsulation?

3.What is class ? 

 

  • A class is a specification or blue print or template of an object.
  • Class is a logical construct , an object has physical reality.
  • Class is a structure.
  • Class is a user defined data type in java
  • Class will acts as base for encapsulation.
  • Class contains variables and methods.


  1. package com.instanceofjava;
  2.  
  3. class Demo{
  4.  
  5. int a,b;
  6. void show(){
  7. }
  8.  
  9. }

4. What is an object?



  • Object is instance of class.
  • Object is dynamic memory allocation of class.
  • Object is an encapsulated form of all non static variables and non static methods of a particular class.
  • The process of creating objects out of class is known as instantiation.
  1. package com.instanceofjava;
  2.  
  3. class Test{
  4.  
  5. int a,b;
  6. void print(){
  7. System.out.println("a="+a);
  8. System.out.println("b="+b);
  9. }
  10.  
  11. public static void main(String [] args){
  12.    
  13.    Test obj= new Test();
  14.   obj.a=10;
  15.   obj.b=20;
  16.   obj.print();
  17. }
  18. }


Output:

  1. a=10
  2. b=20

5. What are the Object Characteristics?

  •  The three key characteristics of Object are
  • State
  • Behavior
  • Identity

State:

  • Instance variables value is called object state.
  • An object state will be changed if instance variables value is changed.

Behavior:

  • Behavior of an object is defined by instance methods.
  • Behavior of an object is depends on the messages passed to it.
  • So an object behavior depends on the instance methods.

Identity:

  • Identity is the hashcode of an object, it is a 32 bit integer number created randomly and assigned to an object by default by JVM.
  • Developer can also generate hashcode of an object based on the state of that object by overriding hashcode() method of java.lang.Object class.
  • Then if state is changed , automatically hashcode will be changed.

6.What is Inheritance?

  • As the name suggests , inheritance means to take something that already made.
  • One of the most important feature of Object oriented Programming. It is the concept that is used for re usability purpose.
  • Getting the properties from one class object to another class object.

7. How inheritance implemented in java?

  • Inheritance can be implemented in JAVA using below two keywords.
    1.extends
    2.implements
  • extends is used for developing inheritance between two classes or two interfaces, and implements keyword is used to develop inheritance between interface and class.


  1. package com.instanceofjava;
  2. class A{
  3.  
  4. }


  1. package com.instanceofjava;
  2. class B extends A{
  3.  
  4. }

8. What are the types of inheritances?

  • There are two types of inheritance
    1.Multilevel Inheritance
    2.Multiple Inheritance

Multilevel Inheritance:

  • Getting the properties from one class object to another class object level wise with some priority is known as multilevel inheritance.



  1. package com.instanceofjava;
  2.  
  3. class A{
  4.  
  5. }
  6.  
  7. class B extends A{
  8.   
  9. }
  10.   
  11. class C extends B{
  12.  
  13. }


Multiple Inheritance:


9. What is polymorphism?

  • Defining multiple methods with same name,
 Static polymorphism:
  • Defining multiple methods with same name with different parameters.
  • Is also known as method overloading.


  1. package com.instanceofjava;
  2. class Demo{
  3.   
  4. void add(){
  5. }
  6.   
  7. void add(int a, int b){
  8. }
  9.  
  10. void add(float a, float b){
  11.   
  12. }
  13. public static void main(String [] args){
  14.  Demo obj= new Demo();
  15.  
  16. obj.add();
  17. obj.add(1,2);
  18. obj.add(1.2f,1.4f);

  19. }

  20. }


 Dynamic Polymorphism:

  • Defining multiple methods with same signature in super class and sub class.
  • The sub most object method will be executed always.


 10. Similarities and differences between this and super keywords?

 this:
  • This is a keyword used to store current object reference.
  • It must be used explicitly if non -static variable and local variables name is same.
  • System.out.print(this); works fine
super:
  • Super is a keyword used to store super class non -static members reference in sub class object.
  • used to separate super class and sub class members if both have same name.
  • System.out.println(super); compilation Error

11.Top 10 interview Questions on Method overriding

12.Top 15 interview programming questions on abstract classes

13.Top 10 interview Question on interfaces

14.Java Quiz

15. Basic Method overloading interview questions in java 

16. Super keyword interview Questions in java

17.Top 10 java Interview questions on final keyword 

18. Top 10 basic interview questions and answers on this keyword

19. Top 20 java interview questions on constructors 

20. 19 Oops concepts explanation with example programs
  1. OOPS Introduction
  2. Encapsulation 
  3. Class and Object
  4. Four different ways to create objects in java 
  5. 5 different places to define object in java
  6. Polymorphism
  7. Method Overriding
  8. Inheritance
  9. Constructor
  10. Constructor Overloading 
  11. Constructor Chaining 
  12. Static constructor
  13. Static Keyword
  14. This Keyword
  15. Super Keyword
  16. Final Keyword
  17. Abstract class and interfaces 
  18. Abstract Class and abstract methods
  19. Interview questions on interfaces in java

  1. Print prime numbers? 
  2. Java Program Find Second highest number in an integer array 
  3. Java Interview Program to find smallest and second smallest number in an array 
  4. Java Coding Interview programming Questions : Java Test on HashMap 
  5. Constructor chaining in java with example programs 
  6. Swap two numbers without using third variable in java 
  7. Find sum of digits in java 
  8. How to create immutable class in java 
  9. AtomicInteger in java 
  10. Check Even or Odd without using modulus and division  
  11. String Reverse Without using String API 
  12. Find Biggest substring in between specified character
  13. Check string is palindrome or not?
  14. Reverse a number in java? 
For more interview programs : Top 60 Java Programs asked in interviews
Read Also:

1. Top 15 Garbage Collection Interview Questions

2. Top 10 Oops Concepts Interview Questions 

3. Top 15 Java Interview Questions on Constructors

4. Top 10 Inheritance Interview Questions

5. Interview Programs on Strings

6. 10 Interesting Core Java Interview Coding Questions and Answers

7. Top 20 Basic Java Interview Questions for Frehsers 

8. Top 10 interview Question on Static keyword. 

9.Top 20 Java interview Questions on Increment and Decrement operators

10.Top 10 Interview Questions on main() method

11. Top 12 Java Experienced interview Programming Questions on Strings

12.Pattern Programs in java Part-1

13.Pattern Programs in java Part-2

14.Pattern Programs in java Part-3 

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

3 comments for Top 20 Oops Concepts Interview Questions

Select Menu