## School Work

Description
Categories
Published

View again

All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
Share
Transcript
Program – 1(A) Aim: -  Write a program to implement Static Polymorphism (Method Overloading). Source Code: -  package staticpolymorphism; public class StaticPolymorphism { void sum(int aint b) { System.out.println(! n Sum is !#(a#b)); \$ void sum(int aint bint c) { System.out.println(! n Sum is !#(a#b#c)); \$  public static void main(String%& args) { StaticPolymorphism ob'ne StaticPolymorphism(); ob'.sum(*+*+*+); ob'.sum(,+,+); \$\$ Output: -  Program – 1(B) Aim: -  Write a program to implement -ynamic Polymorphism (Method Overriding). Source Code: -  package dynamicpolymorphism;class nimal {  public void move() { System.out.println(!nimals can move!); \$\$class -og e/tends nimal { public void move() { System.out.println(!-ogs can alk and run!); \$\$ public class -ynamicPolymorphism { public static void main(String%& args) { nimal a  ne nimal(); 00 nimal re1erence and ob'ect nimal b  ne -og(); 00 nimal re1erence but -og ob'ect a.move();00output2 nimals can move b.move();00output2 -ogs can alk and run \$\$ Output: -  Program - 2 Aim: -  Write a program to implement bstract class and 3nter1ace. Source Code: -  package animal; inter1ace 4egs{ void no5o15legs();\$abstract class nimal {  public void move(){ \$\$class -og e/tends nimal implements 4egs { public void move() { System.out.println(!-ogs can alk and run.!); \$ public void no5o15legs(){ System.out.println(!-ogs have 6 legs.!); \$ public static void main(String%& args) { -og d  ne -og(); 00 -og ob'ect d.move(); 00 Output2 -ogs can alk and run d.no5o15legs(); 00 Output2 -ogs have 6 legs \$\$ Output: -  Program - 3 Aim: -  Write a program to implement 7/ception 8andling. Source Code: -  package e/ample; import 'ava.io.9; public class Main { public static void main(String%& args) { int ab; -ata3nputStream inne -ata3nputStream(System.in); try { System.out.println(!7nter the values o1 a 2 !); a 3nteger.parse3nt(in.read4ine()); System.out.println(!7nter the values o1 b 2 !); b 3nteger.parse3nt(in.read4ine()); 1loat ca0b; System.out.println(c); \$ catch(7/ception e) { System.out.println(!-ivide by :ero e/ception!#e); \$ \$\$ Output: -

Jul 23, 2017

#### dse

Jul 23, 2017
Search
Similar documents

View more...
Tags

Related Search