11/10/11

Problem Set Java

 Predict the Output  


 Question 1


class Base {
    public void Print() {
        System.out.println("Base");
    }
}
class Derived extends Base {
    public void Print() {
        System.out.println("Derived");
    }
}
class Main{
    public static void DoPrint( Base o ) {
        o.Print();
    }
    public static void main(String[] args) {
        Base x = new Base();
        Base y = new Derived();
        Derived z = new Derived();
        DoPrint(x);
        DoPrint(y);
        DoPrint(z);
    }
}




Question 2


public class otpur {

    public static void main(String[] args) {
            int a=4;
            cha(a);
            System.out.println(a);
    }
    
    public static void cha(int a){
        System.out.println(++a);
    }
}




Farhan Khwaja Article by Farhan Khwaja 
Farhan has written 71 articles .
If you like This post, you can follow Code 2 Learn on Twitter.
Subscribe to Code 2 Learn feed via RSS or EMAIL to receive instant updates.
Want to write for Code 2 Learn. Read here for more info

SHARE THIS POST: