- // this is my first oops code try creat a objeactpublic class Oops {int a ;String rakesh;public static void main(String[] args) {Oops obj = new Oops();Oops obj1 = new Oops();System.out.println(obj.rakesh);System.out.println(obj.a);System.out.println(obj1.rakesh);}}
- // try to exchange object value in instance variable;public class oops1 {int Number = 25;String Name = "Rakesh";public static void main(String[] args) {oops1 obj = new oops1();obj.Name = "Pankaj";System.out.println(obj.Name);System.out.println(obj.Number);}}
- // i am using addition class in java code and its worksclass calc{int Number = 33;String Name = "rakesh";}public class oops2 {public static void main(String[] args) {calc obj = new calc();System.out.println(obj.Number);System.out.println(obj.Name);}}
- // this sesion i learn about over loding that how desgine a calculater and how to reuse 1 methode and how again and again perfome instance variableclass calc {public int add (int a, int b){int result = a+b;return result;}public int add (int a, int b,int c ){int result = a+b+c;return result;}public double add (double a, double b, double c ){double result = a+b+c;return result;}}public class overloding {public static void main(String[] args) {calc obj = new calc();int result = obj.add(5,8);System.out.println(result);// this result is deffrent because instance variabel and local varial is difrrent and you use here result you shall no faca any issueint result1=obj.add(5,8,6);System.out.println(result1);// and this statement dedicate to perform double type you should use double type so you will allready declare double type datadouble result2 = obj.add (4.5, 8.5,8.5);System.out.println(result2);}}
- // i am using import methode using overloadingimport java.util.Scanner;class calculator{public int add(int a , int b,int c){int result = a+b+c;return result;}}public class overloding_input {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int a = sc.nextInt();int b=sc.nextInt();int c = sc.nextInt();calculator obj = new calculator();int result = obj.add(a,b,c);System.err.println(result);sc.close();}}// input 85// 45// 85// output 215