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.
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 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.
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();
}
}
Output:
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