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:

Related Posts:

  • Problem Set 3 The below questions are very interesting and amazing questions. So please do try it. QUESTION 1 int a=5,*b=&a;printf("%d",a**b); !-- google_ad_client = "ca-pub-0770336576285658"; /* inside post */ goog… Read More
  • Problem No.1 The below program is hideously slow. CAN YOU SPOT THE REASON? public static void main(String args[]){ Long sum=0L; for ( long i=0; i < Integer.MAX_VALUE; i++){ sum += i; } System.out.pri… Read More
  • 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("D… Read More
  • Find the largest sum in an Array Problem $(document).ready(function(){ $(".flip").click(function(){ $(".panel").slideToggle("slow"); }); }); div.panel,p.flip { margin:0px; padding:5px; text-align:center; background:#e5eecc; border:solid 1px #c3c3c3; … Read More
  • Java Problem Set 2 Write a function which calculates the sum of even Fibonacci numbers. public static void main(String args[]) { for(int i=1;i<22;i++) System.out.print(sumofEvenFibonacci(i) + " "); } public static long sumofE… Read More