Navigation Links

Responsive Topnav Example

Resize the browser window to see how it works.

Showing posts with label Java OOPS. Show all posts
Showing posts with label Java OOPS. Show all posts

Monday, March 25, 2013

Java OOPS Keypoints


Object  -
 object is a software bundle of related state and behaviour.
 software object are often used to model the real world object that we find in everyday life.

class
 class is a blueprint or prototype from which object or created.

Inheritance
 How the class inherit the state and behaviour of super class.

Interface:
 Interface is a contract between class and outside world.
 when class implement an interface, it promises to provide the behaviour published by that interface.

package
  package is a placing class and interface in logical manner.
  it manage large software project if their class and interface into package.

Example of abstract class in java



Below Program explain example of abstract class in java


package com.thanu.welcome;

/*
 * Abstract Class Example.
 * Abstract class have Abstract method or method implementation.
 * It can't be instantated, But we can be subclassed. Also, we can access static method from abstract class
 * But Subclass must implemented abstract method of abstract class.Otherwise, it will be abstract
 * Different b/w Abstract class or interface.
 * In Abstract class can have method implemented, and abstract methods. But interface have only method definintion.
 * Interface have only static and Final Variables. But Absract class any one variable.
 * Situation for using abstract class:
 * In Object oriented Drawing Application:
 * Some Object have common behavior and some object have different behaviour.
 * For ex: Fillcolor,MoveTo,position is same for circle,rectanlge,triangle
 * draw,resize will be different behavior for circle, rechtangle, trigangle
 * Same behaviour can be implemented , different behaviour will be abstract method.
 */
abstract class MyAbstract {
int a,b;

//Method Implementation in Abstract Class
void fillColor (int x, int y) {

System.out.println("This is fillColor method " + x +" "+  y);
}
//Static method in MyAbstract Class
static void printValue() {
System.out.println("Just simply printing value static method");
}

//Method Definition in Abstract Class
abstract void draw(int x, int y);
abstract void resize(int x,int y);
}


public class ExampleAbstractClass extends MyAbstract {

public static void main (String arg[]) {

System.out.println("Many more welcome to our website");

//Calling static method from Abstract Method
MyAbstract.printValue();

//Create object for base class
ExampleAbstractClass instance = new ExampleAbstractClass();

//calling Abstract Class Implemented Method
instance.fillColor(10,20);

instance.draw(20,30);

instance.resize(40,50);



}

void draw (int x, int y) {
System.out.println("Implementation of draw method");
}
void resize(int x,int y) {
System.out.println("Implementation of resize method");

}


}