Select the correct answerWhat will be the output of the following Java code? class overload { int Code; int Tantra; void add(int x) { Code = x + 1; } void add(int x, int y) { Code = x + 2; } } class Overload_methods { public static void main(String args[]) { overload obj = new overload(); int Code = 0; obj.add(6); System.out.println(obj.Code); } }Options7658
Question
Select the correct answerWhat will be the output of the following Java code? class overload { int Code; int Tantra; void add(int x) { Code = x + 1; } void add(int x, int y) { Code = x + 2; } } class Overload_methods { public static void main(String args[]) { overload obj = new overload(); int Code = 0; obj.add(6); System.out.println(obj.Code); } }Options7658
Solution
The correct answer is 7.
Here's the step by step explanation:
- An object of the class 'overload' is created.
- The method 'add' with a single parameter is called with the argument 6.
- Inside the method, the value of 'x' is incremented by 1 and assigned to the instance variable 'Code'.
- Therefore, the value of 'Code' becomes 6 + 1 = 7.
- This value is then printed out, so the output of the code is 7.
Similar Questions
Select the correct answerWhat will be the output of the following Java program? class static_out { static int x; static int y; void add(int a , int b) { x = a + b; y = x + b; } } class static_use { public static void main(String args[]) { static_out obj1 = new static_out(); static_out obj2 = new static_out(); int a = 2; obj1.add(a, a + 1); obj2.add(5, a); System.out.println(obj1.x + " " + obj2.y); } }Options7 9 6 67 79 7
e correct answerWhat will be the output of the following Java code? class Codetantra { final public int output(int x, int y) { return 1; } } class Program extends Codetantra { public int output(int x, int y) { return 2; } } public class result { public static void main(String args[]) { Program object = new Program(); System.out.print("y is " + y.output(0, 1)); } }
Select the correct answerWhat will be the output of the following Java program? class access { static int x; void increment() { x++; } } class static_use { public static void main(String args[]) { access obj1 = new access(); access obj2 = new access(); obj1.x = 0; obj1.increment(); obj2.increment(); System.out.println(obj1.x + " " + obj2.x); } }Options 2 21 11 2Compilation Error
What is method overloading in java?Question 14Answera.Defining a method in a subclass with the same signature as in its super class.b.Inheriting methods from a super class.c.Creating multiple constructors in the same class.d.Defining multiple methods with the same name but different parameter lists
Distinguish between method over ridding and method overloading as used in objectedoriented programming languages such as java. Give an example java code implementingfor each case
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.