Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
javaSuperSub
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'. //openjdk version '11.0.5' ////////////////////////////////////////////////////////////////////////////////javaSupSub:Super Class,Sub Class and Polymorphism in Java //this code is created by Rezaul Hoque on September 22,2022; //contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; ////////////////////////////////////////////////////////////////////////////// import java.util.*; import java.lang.*; class Demo{ protected String name; protected int id; protected int phone; public Demo(){ } public Demo(String n,int a,int c){ this.name=n; this.id=a; this.phone=c; } public String getN(){return name;} public int getID(){return id;} public int getP(){return phone;} public void category(){System.out.println("None");} } class Sub1 extends Demo{ public Sub1(){ super(); } public Sub1(String n,int a,int c){ super.name=n; super.id=a; super.phone=c; } @Override public void category(){System.out.println("Professional");} } class Sub2 extends Demo{ public Sub2(){ super(); } public Sub2(String n,int a,int c){ super(n,a,c); } @Override public void category(){System.out.println("Personal");} } class Rextester { public static void main(String args[]) { Demo e1,e2,e3; e1= new Sub1("XYZ",89,12345); e2= new Sub2("FGH",90,54321); e3= new Sub2("QWE",21,45678); Demo[] demos={e1,e2,e3}; System.out.println("ID\tName\tPhone\tCategory"); for(Demo ex: demos){ System.out.printf("%d\t%s\t%d\t",ex.getID(),ex.getN(),ex.getP()); ex.category(); } } }
[
+
]
Show input
Compilation time: 1.13 sec, absolute running time: 0.27 sec, cpu time: 0.18 sec, memory peak: 36 Mb, absolute service time: 1,46 sec
edit mode
|
history
|
discussion
ID Name Phone Category 89 XYZ 12345 Professional 90 FGH 54321 Personal 21 QWE 45678 Personal