*Java Constructor* 


class Main {

  private String name;

  Main() {

     name = "Programiz";

  }


  public static void main(String[] args) {

   

    Main obj = new Main();

    System.out.println("The name is " + obj.name);

  }

}

Output:


Constructor Called:

The name is Programiz


Method over riding 


class Animal{  

void eat(){System.out.println("eating...");}  

}  

class Dog extends Animal{  

void bark(){System.out.println("barking...");}  

}  

class TestInheritance{  

public static void main(String args[]){  

Dog d=new Dog();  

d.bark();  

d.eat();  

}}

Output:

barking...

eating...