From fab39307b045215fb465701009bb0d454788a4ca Mon Sep 17 00:00:00 2001 From: Kamal Wickramanayake Date: Sat, 21 Feb 2026 19:56:23 +0530 Subject: Added simple OOP sample code. --- oop/02-non-static-methods/.gitignore | 1 + oop/02-non-static-methods/Calculator.java | 15 +++++++++++++++ oop/02-non-static-methods/MyApp.java | 13 +++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 oop/02-non-static-methods/.gitignore create mode 100644 oop/02-non-static-methods/Calculator.java create mode 100644 oop/02-non-static-methods/MyApp.java (limited to 'oop/02-non-static-methods') diff --git a/oop/02-non-static-methods/.gitignore b/oop/02-non-static-methods/.gitignore new file mode 100644 index 0000000..6b468b6 --- /dev/null +++ b/oop/02-non-static-methods/.gitignore @@ -0,0 +1 @@ +*.class diff --git a/oop/02-non-static-methods/Calculator.java b/oop/02-non-static-methods/Calculator.java new file mode 100644 index 0000000..ecc7234 --- /dev/null +++ b/oop/02-non-static-methods/Calculator.java @@ -0,0 +1,15 @@ + +public class Calculator { + + public int add(int a, int b) { + return a + b; + } + + public int subtract(int a, int b) { + return a - b; + } + + public double convertFromC2F(double cTemp) { + return cTemp*180/100 + 32.0; + } +} diff --git a/oop/02-non-static-methods/MyApp.java b/oop/02-non-static-methods/MyApp.java new file mode 100644 index 0000000..2ebdcae --- /dev/null +++ b/oop/02-non-static-methods/MyApp.java @@ -0,0 +1,13 @@ + +public class MyApp { + + /** + * @param args + */ + public static void main(String[] args) { + Calculator cal = new Calculator(); + + System.out.println(cal.convertFromC2F(100.0)); + } + +} -- cgit v1.2.3