Rabu, 06 Juli 2016

Java Interview programming questions on this keyword

  • Lets discuss some interesting programs on this keyword.
  • Now its time to practice some programs on this keyword. 
  • Try to guess the output of the following java programming questions on this keyword.
  • If you want explanations for all the programs please go through this keyword interview questions on java
Java Quiz on this keyword part #1



Program #1: Java interview programming question on this keyword.


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

  20. }
  21.  
  22. }





Program #2: Java interview programming question on this keyword.

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

  20. }
  21.  
  22. }




Program #3: Java Interview programming example on this keyword.

  • What will be the output of the below program

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

  20. }
  21.  
  22. }





Program #4: Java interview programming question on this keyword.


java programming examples on this keyword




  1. Zero argument constructor called.
  2. Two argument constructor called.
  3. x=1
  4. y=2

Interview Programming questions on this keyword part 2

Bagikan

Jangan lewatkan

Java Interview programming questions on this keyword
4/ 5
Oleh

Subscribe via email

Suka dengan artikel di atas? Tambahkan email Anda untuk berlangganan.