You must Sign In to post a response.
  • Category: General

    Questions on oop's concept


    Kindly let me know the answers for the questions that i have faced in my interview.

    1)In a program i have two methods, one is absract method and the other one is interface method. Now i will interhit both absract method and interface method into a class. Out these two methods which one will be executed first and why.

    Note: sorry, i don't excatly remember the question that he has asked whether we inherit those
    method's into a class or another method.

    Method1: abstract
    int a

    Method2: interface
    int a

    class : abstract, interface Note:which of these method will be called or executed first
    { in the class and why.


    2)In a program two variables will be assigned with the values a=10 and b=5.In output we should get a=5 and b=10. How can we get it.

    kindly tell me the answers for above questions and also tell me some such type of questions,that we would face in the interview.and help me to prepare for the interview.

  • #760948
    Hi Rohini.

    Your first question is not clear.
    Remember the question and provide exact requirement.

    For 2nd question, you need to swap the numbers like below.

    using System ;
    using System.Collections.Generic ;
    using System.Linq ;
    using System.Text ;
    namespace Program
    class Program
    static void Main ( string [] args )
    int a, b, temp ;
    a= 5;
    temp = a;
    a= b;
    b= temp ;
    Console .Write ( " \nAfter Swapping : " );
    Console .Write ( " \na:" +a );
    Console .Write ( " \nb :" +b );
    Console .Read ();
    Here is the output:
    After Swapping :
    a: 10
    b: 5


    Sridhar Thota.
    "Poverty means Poverty of knowledge"

    Sridhar Thota.
    Editor: DNS Forum.

  • #760965
    Hello Rohini,

    Tell us your first question properly for exact answer from us.

    2nd question's answer :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleApplication1
    class Program
    static void Main(string[] args)
    int a = 10, b = 5, temp;

    Console.WriteLine("Before swapping :");
    Console.WriteLine("a = " + a);
    Console.WriteLine("b = " + b);

    temp = a;
    a = b;
    b = temp;

    Console.WriteLine("\nAfter swapping : ");
    Console.WriteLine("a = " + a);
    Console.WriteLine("b = " + b);

    Console.WriteLine("\nPress any key to exit...");


    Hope this will help you.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #760967
    for swapping there are few more options. you can check following link

    usualy the question will be swaping two numbers without thrird vaiable

    Do Good... Enjoy your life.....

  • #761192

    Abstract class:
    *Abstract class can contain both abstract
    methods and non abstract methods.
    *If a class contains at least one abstract method
    then that class must be declared as abstract
    *Abstract class can inherit from another abstract
    class and can inherit from more than one
    *Abstract methods must be implemented in
    derived class.
    *Object cannot be created for abstract classes,
    reference can be created.
    public abstract class myabstract: IA, IB //IA
    and IB are two interfaces
    public abstract viod m1(); //abstract method
    public void m2() //non abstract method
    //some logic

    *Interface contain only abstract methods, which
    are public abstract by default.
    *Interface can implement another interface but
    cannot implement abstract class.
    *Object cannot be created for interface, reference
    can be created.
    public interface ISample:IMysample
    void mymethod();
    void mymethod2();


    Thota Sridhar.
    If you learn from defeat..
    You haven't really lost..

    Sridhar Thota.
    Editor: DNS Forum.

  • Sign In to post your comments