Interview questions related to c++,java

Let us some c,c++ and java

Here we will discuss some commonly asked questions in interviews related to c,c++ and java that will help a lot of ceans in furture interview that they will attend

so here goes 1st question

In c++ there are virtual destructors but not virtual constructors why?

Answer with proper explanation with any suitable example will be appreciated...

Replies

  • HImanshu_Sharma
    HImanshu_Sharma
    A destructor is a member function of a class, which gets called when the object goes out of scope". This means all clean ups and final steps of class destruction are to be done in destructor. A virtual function is something which helps a derived class in overriding the implementation of a functionality of a base class.
    there are two types of desctructors
    1. Derived class destructor
    2. Base class destructor
    A difference between a destructor (of course also the constructor) and other member functions is that, if a regular member function has a body at the derived class, only the version at Derived class gets executed. Whereas in case of destructors, both derived as well as base class versions get executed.
    now the question is why destructor should be virtual?
    so the answer is,,,destructor should be virtual so that we don't have to use implementation methods or interface..
    A virtual constructor would be meaningless in C++.Declaring something virtual in C++ means that it can be overridden by a sub-class of the current class however the constructor is called when the objected is created at that time you can not be creating a sub-class of the class you must be creating the class so there would never be any need to declare a constructor virtual.
  • sookie
    sookie
    Few questions of Java
    - Why strings are immutable?
    - What will be the output?
     
    class A{
    public void method1(){
    System.out.println("Method 1 of A");
    }
    }
    class B extends A{
    public void method1(){
    System.out.println("Method1 of B");
    }
    }
    public class Test{
    public static void main(String[] args){
    A a =new B();
    a.method1();
    }
    }
    
  • savitha_chandu
    savitha_chandu
    What are Transient and Volatile Modifiers?
    Ans: Transient: The transient modifier applies to variables only and it is not stored as part of its object's Persistent state. Transient variables are not serialized.
    Volatile: Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.
  • Manish Goyal
    Manish Goyal
    @ Sookie output should be
    Method1 of B
  • sherya mathur
    sherya mathur
    Questions on java frequently asked in interviews:
    1:What is session tracking and how do you track a user session in servlets?

    Session tracking is a mechanism that servlets use to maintain state about a series requests from the same user across some period of time. The methods used for session tracking are: a) User Authentication - occurs when a web server restricts access to some of its resources to only those clients that log in using a recognized username and password. b) Hidden form fields - fields are added to an HTML form that are not displayed in the client’s browser. When the form containing the fields is submitted, the fields are sent back to the server. c) URL rewriting - every URL that the user clicks on is dynamically modified or rewritten to include extra information. The extra information can be in the form of extra path information, added parameters or some custom, server-specific URL change. d) Cookies - a bit of information that is sent by a web server to a browser and which can later be read back from that browser. e) HttpSession- places a limit on the number of sessions that can exist in memory. This limit is set in the session. maxresidents property.
    2:What is Server-Side Includes (SSI)?
    Server-Side Includes allows embedding servlets within HTML pages using a special servlet tag. In many servlets that support servlets, a page can be processed by the server to include output from servlets at certain points inside the HTML page. This is accomplished using a special internal SSINCLUDE, which processes the servlet tags. SSINCLUDE servlet will be invoked whenever a file with an. shtml extension is requested. So HTML files that include server-side includes must be stored with an . shtml extension

You are reading an archived discussion.

Related Posts

Hello friends, I would like to know if it is possible to modify an existing die from injection moulding. For example, if I find an obsolete plastic product and like...
I am doing my final year B-tech in information technology.currently my last minor project based on web design.so I am searching for a good minor project topic in web design.I...
hi friends, is it possible to make .gif file and .jpeg from applet ? if yes then how. . 😁
Hello everyone, My name Stag, I leave in Chicago I like the crazyengineers forum what a nice forum with lots of knowledge and information. ----------------------------------------------------------------------- Plastic Injection Molding
Can anyone give me a part ( mechanism) in an aircraft that has between 5-20 parts for a mechanical engineering project thanks -------------------------------------------------------------- Plastic Injection Molding