The Artima Developer Community
Sponsored Link

Java Buzz Forum
10 Tricky Core Java Interview Coding Questions

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.
10 Tricky Core Java Interview Coding Questions Posted: May 8, 2015 8:09 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: 10 Tricky Core Java Interview Coding Questions
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
1. What is the output of following program?

  1. package com.instanceofjava;
  2.  
  3. public class B{
  4.  
  5.   B b= new B();
  6.  
  7.  public void show(){
  8.         System.out.println("show method called");
  9.  }
  10.  
  11.  public static void main(String[] args)  {
  12.         B b= new B();
  13.         b.show();
  14.     }
  15.  
  16. }

Click for Output


Exaplanation:

  • Whenever we create the object of any class constructor will be called first and memory allocated for all non static variables
  • Here  B b= new B(); variable is object and assigned to new object of same class
  • B b= new B(); statement leads to recursive execution of constructor will create infinite objects so at run time an exception will be raised
  • Exception in thread "main" java.lang.StackOverflowError
  • The common cause for a stack overflow exception  is a bad recursive call. Typically this is caused when your recursive functions doesn't have the correct termination condition






Read: 10 Tricky Core Java Interview Coding Questions

Topic: 10 ways our data overlords could serve us better Previous Topic   Next Topic Topic: Java Code Geeks are giving away FREE copies of their JSF 2.0 Programming Cookbook eBook!

Sponsored Links



Google
  Web Artima.com   

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