Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
MyBirdClass
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Bird{ protected static int counter=0; protected String birdName; protected String bodyColor, beakColor; protected boolean canFly; public Bird(){ counter++;} public Bird(String bn, String bc, String bkc,boolean cf) { birdName=bn; bodyColor=bc; beakColor=bkc; canFly=cf; counter++; } public void fly(int height) { System.out.println("I am "+ birdName+" flying at "+ height+" feet high in the sky"); } public String getBirdName( ) { return birdName;} public static int getCount(){ return counter; } } class SingingBird extends Bird{ public SingingBird(String bn,String bc, String bkc, boolean cf) { super(bn,bc,bkc,cf); } } class Rextester { public static void main(String args[]) { Bird b1=new Bird("Parrot","Green","Red",true); b1.fly(200); SingingBird b2=new SingingBird("Ninghtingale","Black","White",true); b2.fly(300); Bird b3=new Bird(); System.out.println("Total number of birds "+Bird.getCount()); System.out.println("I am a "+b2.getBirdName()); } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Abhay
Java Class and Object
simple date time in java
bit left 2
Draw rectangle using for loop
Fibonacci 2
binary search
1a
Minimo quadrato somma di cubi
Implement Queue with Limited Size of Arrays
stackse - search stackoverflow differently
Please log in to post a comment.