adplus-dvertising
frame-decoration

Question

Correct code to be added for overloaded operator – for C# .net code given below is?
class csharp
 {
     int x, y, z;
     public csharp()
     {
 
     }
     public csharp(int a ,int b ,int c)
     {
         x = a;
         y = b;
         z = c;
     }
     Add correct set of code here
    public void display()
    {
        console.writeline(x + "  " + y + "  " + z);
    }
    class program
    {
        static void Main(String[] args)
        {
            csharp s1 = new csharp(5 ,6 ,8);
            csharp s3 = new csharp();
            s3 = - s1;
            s3.display();
        }
    }
}

a)
 public static csharp operator -(csharp s1)
    {
        csharp t = new csharp();
        t.x = s1.x;
        t.y = s1.y;
        t.z = -s1.z;
        return t;
    }

b)
 public static csharp operator -(csharp s1)
    {
        csharp t = new csharp();
        t.x = s1.x;
        t.y = s1.y;
        t.z = s1.z;
        return t;
    }

c)
public static csharp operator -(csharp s1)
    {
        csharp t = new csharp();
        t.x = -s1.x;
        t.y = -s1.y;
        t.z = -s1.z;
        return t;
    }

a.

a

b.

b

c.

c

d.

None of the mentioned

Posted under C# programming

Answer: (c).c

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. Correct code to be added for overloaded operator – for C# .net code given below is?

Similar Questions

Discover Related MCQs

Q. Selecting appropriate method out of number of overloaded methods by matching arguments in terms of number ,type and order and binding that selected method to object at compile time is called?

Q. Wrong statement about run time polymorphism is?

Q. Choose the correct statement among the following which supports the fact that C# does not allow the creation of empty structures?

Q. Choose the correct statement about structures as to why they are defined as value types but not reference types?

Q. Choose the wrong statement about structures in C#.NET?

Q. When does a structure variable get destroyed?

Q. Select the wrong statements among the following?

Q. Choose the correct statements about enum used in C#.NET?

Q. Which among the following cannot be used as a datatype for an enum in C#.NET?

Q. Wrong statement about enum used in C#.NET is?

Q. Choose the correct statement about enum used in C#.NET ?

Q. Which among the following differentiates enum in C#.NET from enum in C language?

Q. Which procedure among the following should be used to implement a ‘Has a’ or a ‘Kind of’ relationship between two entities?

Q. The number of levels of inheritance are?

Q. In an inheritance chain through which of following, the base class and its components are accessible to the derived class?

Q. Select the class visibility modifiers among the following :

Q. In Inheritance concept, which of the following members of base class are accessible to derived class members?

Q. Wrong statement about inheritance in C# .NET?

Q. A class member declared protected becomes member of subclass of which type?

Q. Which of the following functionality is facilitated by inheritance mechanism?