- Java programming interview questions and answers on this keyword
- We have some list of java programs on this keyword in
- Java interview programming questions on this keyword part 1
- Java interview programming questions on this keyword part 2
- Let us see remaining java programs on this keyword
Java Quiz on this keyword part #3
Program #9: Is it possible to Pass this as parameter of a method?
- package thiskeywordinterviewprograms.java;
- public class ThisDemo {
- int a,b;
- public ThisDemo Show(){
- this.a=10;
- this.b=20;
- return this;
- }
- public static void main(String[] args) {
- ThisDemo obj = new ThisDemo();
- System.out.println("a="+obj.a);
- System.out.println("b="+obj.b);
- ThisDemo obj1 = obj.Show();
- System.out.println("a="+obj1.a);
- System.out.println("b="+obj1.b);
- }
- }
Program #10: Is is possible to access static variables and static methods using this keyword?
Program #11:Java program to test whether we can use this in static block or not?
- package thiskeywordinterviewprograms.java;
- public class ThisDemo {
- static int a,b;
- static{
- this.a=10;
- this.b=20;
- }
- public static void main(String[] args) {
- ThisDemo obj = new ThisDemo();
- System.out.println("a="+obj.a);
- System.out.println("b="+obj.b);
- }
- }
Program #12: Java interview program to test whether we can use this in static methods?
- package thiskeywordinterviewprograms.java;
- public class ThisDemo {
- static int a,b;
- public static void main(String[] args) {
- ThisDemo obj = new ThisDemo();
- this.a=10;
- this.b=20;
- System.out.println("a="+obj.a);
- System.out.println("b="+obj.b);
- }
- }
No comments