Tutorial I: Ans: Opening Braces (Is Not Given
Tutorial I: Ans: Opening Braces (Is Not Given
b) Class ABC
{
public int x;
protected private y;
}
Ans:
Datatype is not specified for y.
c) Class xyz
{
public const int x;
public static int y;
}
Ans:
Value for constant variable x is not specified.
d) Class ABC
{
int x=1;
int y=x+1;
}
Ans:
No error in initialization
e) Class ABC
{
static int x=1,y,z=2;
new double p=2.5;
}
Ans:
Error access modifier cannot be new
Ans:
Error in initialization.
Class AB
{
int x=0;
public Void F()
{
int x=10;
Console.WriteLine(x);
}
}
Ans:
since X is not public to class AB
Method F() uses only value in it.
9.Create a class named integer to hold two integer values. Design a method swap
that could take two integer objects as parameters and swap their contents. Write a main
program to implement the class integer and the method swap.
using System;
Class Integer
{
public int a;
public int b;
public int temp;
public void swap(int x,int y)
{
a=x;
b=y;
temp=a;
a=b;
b=temp;
}
public static void Main()
{
integer i =new Integer();
int a=100;
int b=200;
I.swap(a,b);
Console.WriteLine(“After swapping:”);
Console.Writeline(“a=+a);
Console.WriteLine(“b=”+b);
}
}
Ans:
After swapping:
a=200
b=100