- 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
Program #1: Java interview programming question on this keyword.
- package thiskeywordinterviewprograms.java;
- public class ThisDemo {
- int a;
- int b;
- ThisDemo(int a, int b){
- a=a;
- b=b;
- }
- public static void main(String[] args) {
- ThisDemo obj = new ThisDemo(10, 20);
- System.out.println(obj.a);
- System.out.println(obj.b);
- }
- }
Program #2: Java interview programming question on this keyword.
- package thiskeywordinterviewprograms.java;
- public class ThisDemo {
- int a;
- int b;
- ThisDemo(int a, int b){
- this.a=a;
- this.b=b;
- }
- public static void main(String[] args) {
- ThisDemo obj = new ThisDemo(10, 20);
- System.out.println(obj.a);
- System.out.println(obj.b);
- }
- }
Program #3: Java Interview programming example on this keyword.
- What will be the output of the below program
- package thiskeywordinterviewprograms.java;
- public class ThisDemo {
- int a;
- int b;
- ThisDemo(int a, int b){
- this.a=a;
- this.b=b;
- }
- public static void main(String[] args) {
- ThisDemo obj = new ThisDemo();
- System.out.println(obj.a);
- System.out.println(obj.b);
- }
- }
Program #4: Java interview programming question on this keyword.
- Zero argument constructor called.
- Two argument constructor called.
- x=1
- y=2
Interview Programming questions on this keyword part 2
Bagikan
Java Interview programming questions on this keyword
4/
5
Oleh
Kris Kimcil