Posts

Showing posts from October, 2015

Programs Using "super" Keyword

Super Keyword Super Keyword is used to refer the immediate parent class object. Super keyword can be used in three Levels : Super at Variable Level Super at Constructor Level. Super at Method Level 1.super Keyword at Variable Level: When we want to call the variable from the super class then such variables can be called using the super keyword and such level of calling a variable is called as super at variable level. Programs Using super Keyword at Variable Level class SuperVariable { String instituteName="Void Main Technologies"; } class SuperVariable1 extends SuperVariable { String instituteName="Institute For all The Technical Courses"; void printDetails() { System.out.println(super.instituteName); // prints the super class variable Value System.out.println(instituteName); } } class SuperVariableLevel extends SuperVariable1 { public static void main(String[] args)  { System.out.println(...

Programs on Inheritance

Image
Inheritance Inheritance is creating the object for one class and acquiring the properties of the parent object . Main theme of inheritance is code reusability . Types of inheritance in java : Single Inheritance. Multilevel Inheritance. Hierarchical Inheritance. Multiple Inheritance. Hybrid Inheritance. Note: Java does not support Multiple and  Hierarchical Inheritance using classes and can be supported using interfaces . Extends is the keyword to perform any type of inheritance. 1.Single Inheritance is a type of inheritance where one child class inherit the properties of one parent class. Programs on Single Inheritance class SingleInheritance  { String nameOfInstitute; String location; public void insertData(String nameOfInstitute,String location) { this.nameOfInstitute=nameOfInstitute; this.location=location; } } class SingleInheritanceTest extends SingleInheritance { public void pr...

Programs Using "this" Keyword

"this" Keyword. "this" keyword is used to specify the current object. It can be used at 3 levels: Variable Level. Constructor Level. Method Level. Note: At any level "this" must be the first statement of a block or scope of the level. Programs Using "this" at Variable Level. when local and instance variables are declared as same then we can use "this" keyword to make difference between them , otherwise the Compiler cant recognize the difference between them and gives a compilation error . class ThisVariable { String name="Void Main Technologies"; void print(String name) { System.out.println("instance values before assigning to local variable:"+this.name+"\n"); this.name=name; System.out.println("instance values after assigning to local variable:"+this.name); } public static void main(String[] args)  { ThisVariable tv=new ThisVariable(); S...