The Artima Developer Community
Sponsored Link

Java Buzz Forum
Java programming interview questions on this keyword part 3

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
Java programming interview questions on this keyword part 3 Posted: Jul 9, 2016 6:35 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Java programming interview questions on this keyword part 3
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement


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. }


Click for Output



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

java programming this keyword


Click for Output


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. }


Click for Output


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. }



Click for Output



Read: Java programming interview questions on this keyword part 3

Topic: The JavaFX Print API Previous Topic   Next Topic Topic: Finished reading: The Slow Regard of Silent Things (The Kingkiller Chronicle, #2.5)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use