1.What are the oops concepts in java?
- Oop is an approach that provides a way of modularizing a program by creating partitioned memory area for both data and methods that can be used as template for creating copies of such modules on demand.
- The four oops concepts are
- Encapsulation
- Polymorphism
- Inheritance
- Abstraction
2. What is encapsulation?
- The process of binding the data with related methods known as encapsulation.
- Class is the base for encapsulation.
- Check here for more points on 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.
- package com.instanceofjava;
- class Demo{
- int a,b;
- void show(){
- }
- }
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.
- package com.instanceofjava;
- class Test{
- int a,b;
- void print(){
- System.out.println("a="+a);
- System.out.println("b="+b);
- }
- public static void main(String [] args){
- Test obj= new Test();
- obj.a=10;
- obj.b=20;
- obj.print();
- }
- }
- a=10
- 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.
- package com.instanceofjava;
- class A{
- }
- package com.instanceofjava;
- class B extends A{
- }
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.
- package com.instanceofjava;
- class A{
- }
- class B extends A{
- }
- class C extends B{
- }
Multiple Inheritance:
- The concept of getting multiple class objects to single class object is known as multiple inheritance. multiple inheritance is not supported by java
- Check here for Why java does not supports 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.
- package com.instanceofjava;
- class Demo{
- void add(){
- }
- void add(int a, int b){
- }
- void add(float a, float b){
- }
- public static void main(String [] args){
- Demo obj= new Demo();
- obj.add();
- obj.add(1,2);
- obj.add(1.2f,1.4f);
- }
- }
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 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
19. Top 20 java interview questions on constructors
20. 19 Oops concepts explanation with example programs
- OOPS Introduction
- Encapsulation
- Class and Object
- Four different ways to create objects in java
- 5 different places to define object in java
- Polymorphism
- Method Overriding
- Inheritance
- Constructor
- Constructor Overloading
- Constructor Chaining
- Static constructor
- Static Keyword
- This Keyword
- Super Keyword
- Final Keyword
- Abstract class and interfaces
- Abstract Class and abstract methods
- Interview questions on interfaces in java
- Print prime numbers?
- Java Program Find Second highest number in an integer array
- Java Interview Program to find smallest and second smallest number in an array
- Java Coding Interview programming Questions : Java Test on HashMap
- Constructor chaining in java with example programs
- Top 10 Interview Programs and questions on method overriding in java
- Swap two numbers without using third variable in java
- Find sum of digits in java
- How to create immutable class in java
- AtomicInteger in java
- Check Even or Odd without using modulus and division
- String Reverse Without using String API
- Find Biggest substring in between specified character
- Check string is palindrome or not?
- Reverse a number in java?
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
THANKS FOR SHARING
ReplyDeleteThanks for sharing such important information
DeleteThanks for giving these concepts
ReplyDelete