The Artima Developer Community
Sponsored Link

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

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 interview programming questions on this keyword part 2 Posted: Jul 6, 2016 12:02 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Java interview programming questions on this keyword part 2
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 #2
  • Java interview program on this keyword: can we call method using this keyword?
  
Program  #5:

java programming on this keyword


Click for Output


Program #6: Can we call non static method from constructor using this?

Java programming examples on this keyword


Click for Output


Program #7: Can we assign something to this ?



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

  22. }
  23.  
  24. }


Click for Output


Program #8 : Can we use this as return statement in a method?


  1. public class B{

  2.    int a;
  3.     
  4.  public int getA() {
  5.         return a;
  6.  }
  7.  
  8. public void setA(int a) {
  9.         this.a = a;
  10. }
  11.  
  12. B show(){
  13.     return this;
  14. }
  15.  
  16. public static void main(String[] args) {
  17.        
  18.  B obj = new B();
  19.  
  20.   obj.setA(10);
  21.  
  22.  System.out.println(obj.getA());
  23.  B obj2= obj.show();
  24.  System.out.println(obj2.getA());
  25.  
  26. }

  27. }

Click for Output



Read: Java interview programming questions on this keyword part 2

Topic: IntelliJ IDEA 2016.2 RC is Out Previous Topic   Next Topic Topic: How to fix

Sponsored Links



Google
  Web Artima.com   

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