Uploaded by Ali Salman

SP19 OOP 101319 63758 A3

advertisement
STUDENT – ID :- 63758.
CLASS – ID :- 101319.
ASSIGNMENT NO. :- 3.
DIFFERENCE BETWEEN C# OOP & JAVA OOP
1st Difference
Properties
In C# : Supported
In Java : Not Supported
C# Code
Java Code
public string Name{
get{
return Name;
}
set{
Name = value;
}
}
// Output:
//Not Supported
STUDENT – ID :- 63758.
CLASS – ID :- 101319.
ASSIGNMENT NO. :- 3.
2nd Difference
Operator Overloading
In C# : Supported
In Java : Not Supported
C# Code
Java Code
static void Main(string[] args){
assestment a_q1 = new assestment();
assestment a_q2 = new assestment();
assestment total = new assestment();
a_q1.setquiz(12.5);
a_q2.setquiz(10);
total = a_q1 + a_q2;
}
class assestment {
private double quiz;
public double getquiz() {
return quiz;
}
public void setquiz(double QUIZ) {
quiz = QUIZ;
}
public static assestment operator
+(assestment q1,assestment q2){
assestment quiz_marks = new assestment();
quiz_marks.quiz = q1.quiz + q2.quiz;
Console.WriteLine(quiz_marks.quiz);
return quiz_marks;
}
// Output: 22.5
//Not Supported
STUDENT – ID :- 63758.
CLASS – ID :- 101319.
ASSIGNMENT NO. :- 3.
3rd Difference
Partial Classes
In C# : Supported
In Java : Not Supported
C# Code
Java Code
class Program
{
static void Main(string[] args)
{
student s = new student();
s.take_data("Ali", 123);
s.display();
Console.ReadKey();
}
}
partial class student
{
string name;
int id;
public void take_data(string name, int id){
this.name = name;
this.id = id;
}
}
partial class student
{
public void display()
{
Console.WriteLine(name + " " + id);
}
}
// Output: Ali 123
//Not Supported
STUDENT – ID :- 63758.
CLASS – ID :- 101319.
ASSIGNMENT NO. :- 3.
4th Difference
Conversions
In C# : Supported
In Java : Not Supported
C# Code
Java Code
Implicit Conversion :
//Implicit conversion.A long can
//hold any value an int can hold,
//and more!
static void Main()
{
int num = 2147483647;
long bigNum = num;
Console.WriteLine(bigNum);
}
// Output: 2147483647
Explicit Conversion :
static void Main()
{
double x = 1234.7;
int a;
// Converting double to int.
a = (int)x;
Console.WriteLine(a);
}
// Output: 1234
//Not Supported
STUDENT – ID :- 63758.
CLASS – ID :- 101319.
ASSIGNMENT NO. :- 3.
5th Difference
Alias
In C# : Supported
In Java : Not Supported
C# Code
Java Code
using c = System.Console;
class Program{
static void Main(string[] args){
c.WriteLine("Sir Qasim Is A Great Teacher");
}
//Not Supported
}
// Output: Sir Qasim Is A Great Teacher
Some More Differences :INSTANCE-LEVEL INNER CLASSES :
C# : Work-around support Instance-level inner classes.
Java : Support for Instance-level inner classes.
ANONYMOUS CLASSES :
C# : Supports statement-level anonymous classes.
Java : Supports implicit anonymous classes.
EVENTS :
C# : Supports events.
Java : Work-around support for events.