Posts

Showing posts from June, 2014

Abstract class,Interfaces and its implementations

Image
Abstract class We need abstract class for the sense of simplicity.Learn it this way,suppose there is a college administration with over 100 of persons working in different sections namely,Head of department,teachers of diff. subjects,accounts department staff,mess staff,cleaners etc. Each have their own role in the college.But,here's the situation,what if the different department(classes) want the similar thing,for example,retrieving student info or getting the salary.We have to make method with similar motive,for each and every class we make,WHAT A WASTE!!! Abstract class comes to the rescue.  Abstract class is nothing but a normal class with some restrictions. Well,these restrictions are: At least one of the method/s must be abstract. You cannot make an object of an abstract class,i.e.,no new keyword before the class name.But the sub-classes of an abstract class is allowed. An abstract method MUST NOT HAVE A BODY.For example:void method(arguments);// there is no braces

The mystery keyword static,final

The keyword static Most of the new java developers are often confused or find difficulty to understand what  keyword static really is. Java API is full of static methods and variables. I will explain it clearly, There are three main reasons why "static" is used: To does not bother about creating an object and accessing methods or data,directly calling the variable or method. To  make the instance variables belonging to whole class rather than binding to a particular object,i.e,if a Class A has static variable a,and A has two instance a1 and a2 with instance variable value then the values are same. To allow sharing of data to all the objects accessing static variable. For c ount the number of objects cr eated in the p rogram as static variables are share d among objects. Where static keyword are used: For making methods static For making class variables static also called static variables For making nested class static. 1.Making methods static:Type stati