Posts

Inheritence in Constructor

  package com.company ; class base { base (){ System . out . println ( "I am a constructor " ); } base ( int a ){ System . out . println ( "I am a over loaded constructor of base class with the value a given is " + a ); } } class Derived extends base { Derived (){ // super(0);//super is a keyword where the only argument constructor will run from the base class System . out . println ( "I am a derived class constructor " ); } Derived ( int x , int y ){ super ( x ); //It takes the value of x from the argument constructor of derived class System . out . println ( "I am a over loaded constructor of derived class with the value y given as " + y ); } } public class Inheritence { public static void main ( String [] args ) { // base b=new base(); Derived der = new Derived ( 10 , 12 ); //First it takes the constructor from the base then it to derived } ...

Inheritence

 Inheritence in Java  package com.company ; class base { //this is base class int x ; public int getX () { return x ; } public void setX ( int x ) { System . out . println ( "I am in base and setting X now " ); this . x = x ; } public void PrintMe (){ System . out . println ( "i am a constructor" ); } } class Derived extends base { //this is inherit the properties of base int y ; public int getY () { return y ; } public void setY ( int y ) { this . y = y ; } } public class Inheritence { public static void main ( String [] args ) { System . out . println ( "Derived class" ); Derived der = new Derived (); der . setX ( 5 ); System . out . println ( der . getX ()); //taking values from the base class der . setY ( 10 ); System . out . println ( der . getY ()); der . PrintMe (); System . out . println ( "Base class" )...