Showing posts from July, 2013

Multilevel Inheritance in java with public variables and parameterized Constructor

This is a demonstration of Multi-level inheritance in java using parameterised constructor
package com.inheritance;

public class Class1 {
public int a;
public int b;
public Class1(int a, int b) {
this.a = a;
this.b = b;
System.out.println("I am super class called first--->"+(a+b));
--------------------------------------------- package com.inheritance; public class Class2 extends Class1 { public int c; public Class2(int a, int b, int c) { super(a, b); this.c=c; System.out.println("I am the second level subclass--->" +a%c); }
} -------------------------------------------------------------- package com.inheritance;
public class Class3 extends Class2 { public int d; public Class3(int a, int b,int c, int d) { super(a, b, c); this.d=d; System.out.println("I am thrid level subclass extends second level class-->"+a*b*c*d); // TODO Auto-generated constructor stub } public static void main(String args[]){ Class3 class3=new Class3(1, 2, 3, 4…