Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
MyBirdClass
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//'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()); } }
[
+
]
Show input
Compilation time: 0.83 sec, absolute running time: 0.14 sec, cpu time: 0.12 sec, memory peak: 18 Mb, absolute service time: 0,98 sec
edit mode
|
history
|
discussion