Access Modifiers in java There are two types of modifiers in java: access modifiers and non-access modifiers. The access modifiers…
Below Program is a Demonstrate usage of Class, Objects, variables and Methods. Calculator Class Source File:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
package com.mypacakage.demo; class CalculatorClass { int val1; int val2; int result; String operation; //Call Below Function after Object creation with arguments //These function will set Result instance variable and display the result //Addition Function public void addition(int arg1, int arg2){ result = arg1+arg2; } //Subtraction Function public void subtraction(int arg1, int arg2){ result = arg1-arg2; } //Multiplication Function public void multiplication(int arg1, int arg2){ result = arg1*arg2; } //Division Function public void division(int arg1, int arg2){ result = arg1/arg2; } //Call any Operation //Function to Demonstrate that while Object is created from other Class Function, //we can set the Class instance variable val1 and val2 and just call the this function public void call_any_ops(char ops){ switch(ops){ case 'A': addition(val1,val2); break; case 'S' : subtraction(val1,val2); break; case 'D' : multiplication(val1,val2); break; case 'M' : division(val1,val2); break; } //Call Show Result Method showresult(); } public void showresult(){ System.out.println("Result of the Operation: " + result); } } |
CalculatorTest Class Source…
Demonstrating Object Classes and Methods Usage Addition and Subtraction as methods of the Public Class Multiplication as Object of Different…
A Java method is a collection of statements that are grouped together to perform an operation. When you call the…
The for Statement The for statement provides a compact way to iterate over a range of values. Programmers often refer…
Q #1) What is Automation Testing? Q #2) What are the benefits of Automation Testing? Q #3) Why should Selenium…
Java String In java, string is basically an object that represents sequence of char values. An array of characters works…
What is Constructor? When the object is created, Java calls the constructor first. Any code you have in your constructor…
What is Eclipse? In the context of computing, Eclipse is an integrated development environment (IDE) for developing applications using the…
Naming a Package With programmers worldwide writing classes and interfaces using the Java programming language, it is likely that…
Java Variables: Java is a strongly typed programming language. This means that every variable must have a data type associated…
Convert using Integer.toString(int) The Integer class has a static method that returns a String object representing the specified int parameter.…
Java Program Hello World To Execute Below Program; put this code in text file. Save as File”name.java”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
class akash{ public static void main(String args[]){ System.out.println("Hello akash"); } } class amit{ public static void main(String args[]){ System.out.println("Hello amit"); } } class sumit{ public static void main(String args[]){ System.out.println("Hello sumit"); } } class vikas{ public static void main(String args[]){ System.out.println("Hello nitin"); } } |
Open…
Java OOPs Concepts In this page, we will learn about basics of OOPs. Object Oriented Programming is a paradigm that…