1) Discuss Overloaded Subprograms concept in C++, C# and Java, with examples and conclusion
2) Discuss Generic Subprograms Subprograms concept in C++, C# and Java, with examples and conclusion.
1. Overloaded Subprograms:
Example Code:
Java:
public class addition {
//function which will take two integer values
public int addition(int x, int y)
{
return (x + y);
}
//function which will take two double values.
public double addition(double x, double y)
{
return (x + y);
}
//main code
public static void main(String args[])
{
addition s = new addition();
System.out.println(s.addition(1, 2));
System.out.println(s.addition(1.5, 2.5));
}
}
Screenshot :
C++
#include <iostream>
using namespace std;
//overloaded class
class additionData {
public:
//function which take two integer input
int addition(int x, int y) {
return x+y;
}
//method which takes two float
float addition(float x,float y) {
return x+y;
}
};
//main
int main(void) {
additionData s;
// Call print to print integer
cout<<s.addition(1,2);
cout<<"\n";
cout<<s.addition(1.5f,2.5f);
}
Screenshot:
C#
using System;
public class additionData {
// method which will take two integer values
public int add(int x, int y)
{
return x + y;
}
//method which will take 2 float values
public float Add(float x,float y)
{
return (x+y);
}
//main
public static void Main(String[] args)
{
additionData s = new additionData();
int sum1 = s.add(1, 2);
Console.WriteLine(sum1);
float sum2 = s.Add(1.5f, 2.5f);
Console.WriteLine(sum2);
}
}
Screenshot:
Conclusion:
2. Generic Subprograms
Examples
Java
//generic class
class TestClass<T>
{
//object of generic class
T o;
//constructor of generic class
TestClass(T o) { this.o = o; }
public T getObject() { return this.o; }
}
//main class
public class Main
{
public static void main (String[] args)
{
//integer type
TestClass <Integer> io = new
TestClass<Integer>(15);
System.out.println(io.getObject());
//string type
TestClass <String> so =
new TestClass<String>("Java code");
System.out.println(so.getObject());
}
}
Screenshot:
C++
#include <iostream>
using namespace std;
//template to print the values
template <typename T>
//print function
T print(T x)
{
return x;
}
// main
int main()
{
cout << print<int>(15) << endl;
cout << print<string>("C++ code") << endl;
return 0;
}
Screenshot:
C#
//generic class
public class TestClass<T> {
private T data;
// using properties
public T value
{
// using accessors
get
{
return this.data;
}
set
{
this.data = value;
}
}
}
// main
class Test {
// Main method
static void Main(string[] args)
{
// string type
TestClass<string> n = new TestClass<string>();
n.value = "C # code";
// integer type
TestClass<float> v = new TestClass<float>();
v.value = 5.0F;
Console.WriteLine(n.value);
Console.WriteLine(v.value);
}
}
Screenshot:
Conclusion:
Friend, this was a really nice question to answer. If you find my answer helpful, please like it. Thanks.
1) Discuss Overloaded Subprograms concept in C++, C# and Java, with examples and conclusion 2) Discuss...
Explain the concept of inheritance in java by providing examples from the real life. You should identify the Superclass and Subclasses in your example
With the use of relevant examples discuss the concept local and static variables in Visual Basic (OOP and EDP)
3. Discuss the concept of viruses and cancer. Include the concept of certain viruses associated with certain cancers and give 3 examples with proper references and citation. Example 1 Example 2 Example 3 References
hapter 4 (2). Identify and discuss real examples of companies with a competitive advantage based on customer lock-in as opposed to product innovation. Which do you expect to sustain a high ROIC for a longer time? Chapter 5 (1). Discuss the three generic sources of a company’s growth, their relative importance for its growth, and what this means for a company’s strategy.
it's a JAVA program. Share Edit & Create aanmethod that tests all three overloaded methods. Save the application as Billing.java. a. Create a FitnessTracker class that includes data fields for a fitness activity the number of minutes spent participating, and the date. The class includes methods to get each field. In addition, create a default constructor that automatically sets the activity to running, the minutes to 0, and the date to January 1 of the current year. Save the file...
Chapter 4 (2). Identify and discuss real examples of companies with a competitive advantage based on customer lock-in as opposed to product innovation. Which do you expect to sustain a high ROIC for a longer time? Chapter 5 (1). Discuss the three generic sources of a company’s growth, their relative importance for its growth, and what this means for a company’s strategy. Add a new discussion topicC
1. discuss the concept of an ecovillage, 2. discuss the qualities of the Earthships or the ecovillage. What did you find attractive and why? What did you find impractical and why? 3. discuss how either of these lifestyle choices could fit into your life. Do you see yourself adopting any part of these lifestyles? Why or why
1. Discuss the concept of morality.
in JAVA 24. Suppose that a class has an overloaded method named add with the following two implementations: double add (int x, double y) { return x + y; } double add (double x, int y) { return x + y + 1; } What, if anything, will be returned by the following method calls? A. add(3, 3.14) B. (3.14, 3) C. add (3, 3) D. add (3.14, 3.14) 29. Here is the code for a recursive method named mystery....
1)Using suitable examples discuss the theories of development 2) Discuss five issues of concern in kenya.