Q:
C#.Net find output programs (Classes & Objects) | set 2
belongs to collection: C#.Net find output programs
C#.Net find output programs
- C#.Net find output programs (Data Types) | set 1
- C#.Net find output programs (Data Types) | set 2
- C#.Net find output programs (Data Types) | set 3
- C#.Net find output programs (Operators) | set 1
- C#.Net find output programs (Operators) | set 2
- C#.Net find output programs (Operators) | set 3
- C#.Net find output programs (const Keyword) | set 1
- C#.Net find output programs (this Keyword) | set 1
- C#.Net find output programs (readonly Keyword) | set 1
- C#.Net find output programs (static Keyword) | set 1
- C#.Net find output programs (static Keyword) | set 2
- C#.Net find output programs (if else) | set 1
- C#.Net find output programs (if else) | set 2
- C#.Net find output programs (if else) | set 3
- C#.Net find output programs (switch statement) | set 1
- C#.Net find output programs (switch statement) | set 2
- C#.Net find output programs (switch statement) | set 3
- C#.Net find output programs (goto) | set 1
- C#.Net find output programs (Loops) | set 1
- C#.Net find output programs (Loops) | set 2
- C#.Net find output programs (Loops) | set 3
- C#.Net find output programs (Arrays) | set 1
- C#.Net find output programs (Arrays) | set 2
- C#.Net find output programs (Arrays) | set 3
- C#.Net find output programs (default Arguments) | set 1
- C#.Net find output programs (default Arguments) | set 2
- C#.Net find output programs (Parameter Passing) | set 1
- C#.Net find output programs (Enumeration) | set 1
- C#.Net find output programs (Enumeration) | set 2
- C#.Net find output programs (Boxing & Unboxing) | set 1
- C#.Net find output programs (Structure) | set 1
- C#.Net find output programs (Structure) | set 2
- C#.Net find output programs (Structure) | set 3
- C#.Net find output programs (Classes & Objects) | set 1
- C#.Net find output programs (Classes & Objects) | set 2
- C#.Net find output programs (Classes & Objects) | set 3
- C#.Net find output programs (Constructors & Destructors) | set 1
- C#.Net find output programs (Constructors & Destructors) | set 2
- C#.Net find output programs (Constructors & Destructors) | set 3
- C#.Net find output programs (Inheritance) | set 1
- C#.Net find output programs (Inheritance) | set 2
- C#.Net find output programs (Inheritance) | set 3
- C#.Net find output programs (Interface) | set 1
- C#.Net find output programs (Interface) | set 2
- C#.Net find output programs (Method Overloading) | set 1
- C#.Net find output programs (Method Overloading) | set 2
- C#.Net find output programs (Method Overriding) | set 1
- C#.Net find output programs (Method Overriding) | set 2
- C#.Net find output programs (Method Overriding) | set 3
- C#.Net find output programs (Operator Overloading) | set 1
- C#.Net find output programs (Operator Overloading) | set 2
- C#.Net find output programs (Operator Overloading) | set 3
- C#.Net find output programs (Namespace) | set 1
- C#.Net find output programs (Namespace) | set 2
- C#.Net find output programs (Exception Handling) | set 1
- C#.Net find output programs (Exception Handling) | set 2
- C#.Net find output programs (Exception Handling) | set 3
Answer 1:
Output:
Explanation:
In the above program, we created a class Sample that contains two private integer data members A and B that are initialized with 5 and 10 respectively. Here, we created two methods set() and print() inside the Sample class.
The set() method is used to set values inside the data members, and the print() method is used to print values of data members on the console screen.
Now look at the Program class, the Main() method contains inside the Program class, which is used as an entry point for the program.
In the Main() method, we created an anonymous object of Sample class and call method using an anonymous object to print the values of A and B on the console screen.
Answer 2:
Output:
Explanation:
In the above program, we created a class Employee that contains three private data members. Here, we created two methods setEmp() and print() inside the Sample class.
The setEmp() method is used to set values of employee data members, and the print() method used to value of employee object.
Now look at the Program class, the Main() method contains inside the Program class, which is used as an entry point for the program.
In the Main() method, we created an object of Employee class.
Here, we set employee id, employee name, and employee salary using the setEmp() method, but here we did not assign the value of salary, the below statement is wrong, because we assigned local variable sal by data member salary.
sal = salary;
The correct statement is given below,
salary = sal;
Then, we call print() method to print employee detail.
Answer 3:
Output:
Explanation:
The above program will generate syntax error because we cannot define methods of a class outside the class.
Answer 4:
Output:
Explanation:
In the above program, we created a class Employee that contains three private data members. Here, we created two methods setEmp() and print() inside the Sample class.
Here, we used access specifier internal. The internal members of the class, can be accessed outside the class.
The setEmp() method is used to set values of employee data members, and the print() method used to value of employee object.
Now look at the Program class, the Main() method contains inside the Program class, which is used as an entry point for the program.
In the Main() method, we created an object of Employee class.
Here, we set employee id, employee name, and employee salary using the setEmp() method and then we call print() method to print employee detail.
Answer 5:
Output:
Explanation:
The above program will generate syntax error because we cannot create a const class in a C# program.
need an explanation for this answer? contact us directly to get an explanation for this answer