Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
javaSuperSub
//'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(); } } }
run
|
edit
|
history
|
help
0
Java Object Info
Coding Challenge - 03 (Prime numbers)
Smallest Multiple of N with Zeros and Ones
1
상속2
Hello world
Account JAVA Cpa
3.c
massive
Coding Numbers - Duplicate - Array