Wednesday, February 2, 2011

lecture #2

http://www.cs.qc.edu/tutors.html

not yet updated

class A
{
public static void main(String args[])
{
Integer x = new Integer(6);
Integer y = 5;
int h[] = new int[1];
int j[] = new int[1];
swap(h, j);
swap(x, y);
System.out.println("" + x + " " + y);
}
// cannot do this; no pointers!
public static void swap(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
// alas, I am copying these references by value
public static void swap(Integer a, Integer b)
{
int temp;
temp = a;
a = new Integer(b.value);
b = new Integer(temp);
}
public static void swap(const int **a, const int **b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}

}

class MutableInteger
{
int value;
}

int retval;
retval = foo(x, y, &g);
if(retval == -1)
{

}
else if (retval == -2)
{


}
else if (retval < 0)
{


}
retval = bar(6, 4, k);
if(retval == -1)
{
cout << "file couldn't open";
exit(1);
}
else if (retval == -2)
{


}
else if (retval < 0)
{


}

foo(x, y, &g);
bar(6, 4, k);


try
{
foo(x, y, &g);
bar(6, 4, k);
}
catch(int i)
{
}
catch(double p)
{

}
catch(...)
{

}

Exception

class Shape
{
public:
virtual void draw() {}
}

class Triangle : public Shape
{
public:
draw() {}
}

class Square : public Shape
{
public:
draw() {}
}

foo(Shape *s)
{
s->draw();
}

main()
{
Shape *s[10];
s[0] = new Triangle();
s[1] = new Square();

}


class F
{
int y;
void foo() {}
public static void main(String args[])
{
F f = new F;
f.y;
f.foo();
}
}

No comments:

Post a Comment