The Artima Developer Community
Sponsored Link

Java Buzz Forum
Top 10 Oops Concepts Interview Questions

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
Top 10 Oops Concepts Interview Questions Posted: Mar 30, 2015 12:43 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Top 10 Oops Concepts Interview Questions
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement

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 three oops concepts are 
  • Encapsulation
  • Polymorphism
  • Inheritance

2. What is encapsulation?

  •  The process of binding the data with related methods known as encapsulation.
  • Class is the base for 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

Read: Top 10 Oops Concepts Interview Questions

Topic: How to batch DELETE statements with Hibernate Previous Topic   Next Topic Topic: Enterprise Golf, or, you get what you pay for, Software Defined Talk #27

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use