Exp 11

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

JAVA

Write a program in JAVA to create a class Bird also declares the different
parameterized constructor to display the name of Birds

package Ladder;

public class ConstructorBird {


int age;
String name;
ConstructorBird()
{
System.out.println("this is the perrot"); }

ConstructorBird(String x) {

name=x; System.out.println("this is the "+name); }

ConstructorBird(int y,String z) {

age=y; name=z;
System.out.println("this is the "+age+"years\t"+name);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ConstructorBird a=new ConstructorBird();
a.ConstructorBird();

ConstructorBird b=new ConstructorBird("maina");

ConstructorBird c=new ConstructorBird(20,"sparrow");


}

private void ConstructorBird() {


// TODO Auto-generated method stub

Viva Questions
Q.1 What is the constructor?
Q.2 How many types of constructors are used in Java?
Q.3 Is constructor inherited?
Q.4 What are the differences between the constructors and methods?

You might also like