Sunday, 29 January 2017

level 2 : 17 Step by step interview question to crack the interview.

IN LEVEL 02 : I WILL USE ALL THE CONCEPT TILL DATE (OOPS, DATA TYPES, INHERITANCE, STATIC, NON- STATIC, OBJECTS  etc.)
1. What will be the output of below code ?
public class callkr {
      
       public void callkr1(Object obj){
              System.out.println("in object method :"+((B)obj).s1);
       }
      
       void callkr1(B b){
              System.out.println("in B method :"+b.s1);
       }
    void callkr1(A a){
       System.out.println("in A method :"+a.s1);
       }
       public static void main(String[] args) {
              A aa=new B();
              new callkr().callkr1(aa);
       }

}


2. What will be the output of the below code ?
class A {public String s1="callkr";
public String show(){
    return "from A : "+s1;
}
}
class B extends A{
       public String s1="javatilldate";
      
       public String show(){
              return "from B : "+s1;
             
       }
}
public class callkr {
      
       public void callkr1(Object obj){
              System.out.println("in object method :"+((B)obj).show());
       }
      
       void callkr1(B b){
              System.out.println("in B method :"+b.show());
       }
    void callkr1(A a){
       System.out.println("in A method :"+a.show());
       }
       public static void main(String[] args) {
              A aa=new B();
              new callkr().callkr1(aa);
       }

}

3. What will be the output of the below code ?
class A {public String s1="calkkr";
public String show(String s1){
    return "from A : "+s1;
}
}
class B extends A{
       public String s1="javatilldate";
      
       public String show(String s1){
              return "from B : "+s1;
             
       }
}
public class callkr {
       static String s1="callkr-again";
      
       public void callkr1(Object obj){
              System.out.println("in object method :"+((B)obj).show(s1));
       }
      
       void callkr1(B b){
              System.out.println("in B method :"+b.show(s1));
       }
    void callkr1(A a){
       System.out.println("in A method :"+a.show(s1));
       }
       public static void main(String[] args) {
              A aa=new B();
              new callkr().callkr1(aa);
       }

}

4. What is Data shadowing ?

5. What is Data Hiding ?

6. What will be the output of the below code ?

class A {public String s1="calkkr";
public String show(String s1){
    return "from A : "+s1;
}
}
class B extends A{
       public String s1="javatilldate";
      
       public String show(String s1){
              return "from B : "+s1;
             
       }
}
public class callkr {
       static String s1="callkr-again";
      
       public void callkr1(Object obj){
              System.out.println("in object method :"+((B)obj).show(s1));
       }
      
       void callkr1(B b){
              System.out.println("in B method :"+b.show(s1));
       }
    void callkr1(A a){
       System.out.println("in A method :"+a.show(s1));
       }
       public static void main(String[] args) {
              A aa=new B();
              aa=null;
              new callkr().callkr1(aa);
       }

}

7. What is java.lang.NullPointerException ?
8. What is dynamic binding ?
9.Can we achieve Dynamic binding with data members ?
10. What will be the output of below code ?
class A {
public String s1="calkkr";
public String show(String s1){
    return "from A : "+s1;
}
}
class B extends A{
       public String s1="javatilldate";
      
       public String show(String s1){
              return "from B : "+s1;
             
       }
      
       public static void main(String[] args) {
              A aa=new B();
             
              System.out.println(aa.s1);
       }
}

1 comment: