Thursday, December 11, 2014

Java Basic Concepts

1. 
Inheritance:
To achieve method overriding there should be inheritance
explanation:
In Child class override the methods declared in parent class

Static Methods can call directly without using create instance (obj) of the class
explanation:
Cal.display();
here Cal is the Class name

2.
Java Bean:
Java Bean is the example of Encapsulation
Hiding Implementation details reduce the complexity and the output is Easier maintenance

3.
Instance Variable : Created on Class level
Class Variable: Created on Class level with static keyword
Local Variable: Created inside the method body

4.
base: this keyword is used to invoke constructor of base class

5.
Interface:

  • Multiple Inheritance can be implemented with the help of Interface.
  • It provide abstractions
  • A contract b/w senior and junior
  • 100% Abstraction
  • It can hold only method prototype (declaration)
  • It can also have var that will be constant
  • The class implementing Interface must have to define all the methods


6.
Abstract:

  • These are the special classes defined with the keyword abstract
  • Use of Abstract Class:
  • When we know about partial implementations


7.
Polymorphism:

  • Ability to take more than one form
  • A child class may override some of the behaviors of the parent class
  • It allows abstract operations to be defined and used

explanation:
abstract operations are defined in base class and used in derived class

declared as abstract or virtual

8.
Package:

  • If the class defined inside the package then the package statement should be the first statement 
  • In simple its a way of categorizing the Classes and Interfaces


9.
Has-A

  • This relationship helps to reduce duplication of code as well as bugs
  • A Class cannot extends more than one class
  • public class extends Animal, Mammal{}  --- It's not possible in Java but can be implemented with the help of Interface

10.
Static:
A method declared static cannot be overridden but can be re-declared.

11.
super
When invoking a super class version of an overridden method the super keyword is used.

12.
Object Declaration:
Animal b = new Dog(); // Animal reference but Dog object
Animal b = new Animal(); //Animal object

No comments:

Post a Comment