» » Java programming interview questions on this keyword part 3



Java Quiz on this keyword part #3

Program #9: Is it possible to Pass this as parameter of a method?

  1. package thiskeywordinterviewprograms.java;
  2.  
  3. public class ThisDemo {
  4.     int a,b;
  5.     
  6. public ThisDemo Show(){
  7.         
  8.   this.a=10;
  9.   this.b=20;
  10.   return this;
  11. }
  12.  
  13. public static void main(String[] args) {
  14.         
  15.     ThisDemo obj = new ThisDemo();
  16.         
  17.   System.out.println("a="+obj.a);
  18.   System.out.println("b="+obj.b);
  19.   ThisDemo obj1 = obj.Show();
  20.         
  21.   System.out.println("a="+obj1.a);
  22.   System.out.println("b="+obj1.b);
  23.         
  24. }
  25.  
  26. }






Program #10: Is is possible to access static variables and static methods using this keyword?

java programming this keyword





Program #11:Java program to test whether we can use this in static block or not?


  1. package thiskeywordinterviewprograms.java;
  2. public class ThisDemo {
  3.  
  4.   static int a,b;
  5.     
  6. static{
  7.     
  8.     this.a=10;
  9.     this.b=20;
  10. }
  11.  
  12. public static void main(String[] args) {
  13.         
  14.   ThisDemo obj = new ThisDemo();
  15.         
  16.   System.out.println("a="+obj.a);
  17.   System.out.println("b="+obj.b);
  18.       
  19.   
  20. }
  21.  
  22. }





Program #12: Java interview program to test whether we can use this in static methods?


  1. package thiskeywordinterviewprograms.java;
  2. public class ThisDemo {
  3.  
  4.     static int a,b;
  5.    
  6.  
  7. public static void main(String[] args) {
  8.  

  9.   ThisDemo obj = new ThisDemo();
  10.    this.a=10;
  11.    this.b=20;    
  12.   System.out.println("a="+obj.a);
  13.   System.out.println("b="+obj.b);
  14.       
  15.     
  16. }
  17.  
  18. }







Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu