Class + Object + Encapsulation + Abstraction code example

Video: ClickMe


Open the eclipse 
Create the new java project Object-Oriented-Programming-OOP-Concepts-in-Java
Add the ClsCalculator.java 
package name:classobject.abstraction.encapsulation.tutorialbyexample.com
class name:ClsCalculator
Click finish



Output:
//ClsCalculator objCalculatorClass = new ClsCalculator();
1 + 1 = 2


ClsCalculator.java 


/** * */ package classobject.abstraction.encapsulation.tutorialbyexample.com; /** * @author Vinod Kumar * */ public class ClsCalculator { /** * Default constructor of ClsCalculator */ public ClsCalculator() { // TODO Auto-generated constructor stub } /** * Addition of two numbers and print the value in console and return the * number as output. * * @param parameter1 * @param parameter2 * @return */ public int addition(int parameter1, int parameter2) { // addResult the local varible for storing the add result and used in // print // method and return. int addResult = parameter1 + parameter2; // Private method for internal use not outside of world print(parameter1, parameter2, addResult); return addResult; } /** * Private method for printing the addition of input and output for abstraction concepts * * @param arg1 * @param arg2 * @param argAdd */ private void print(int arg1, int arg2, int argAdd) { System.out.println("" + arg1 + " + " + arg2 + " = " + argAdd); } }
MainAppOfCalculator.java
/** * */ package classobject.abstraction.encapsulation.tutorialbyexample.com; /** * @author Vinod Kumar * */ public class MainAppOfCalculator { /** * Default Constructor of MainAppOfCalculator */ public MainAppOfCalculator() { // TODO Auto-generated constructor stub } /** * Main method for creation the instance of {@link ClsCalculator} * ClsCalculator instance as object * * @param a */ public static void main(String a[]) { // Creating the instance of ClsCalculator() class. ClsCalculator objCalculatorClass = new ClsCalculator(); // Calling the addition method with two parameter objCalculatorClass.addition(1, 1); } }

No comments:

Post a Comment

Please provide your input, it will honer for me...