65 Responses

Page 1 of 1
  1. sai rakshith reddy
    October 22, 2013 at 7:51 pm | | Reply

    can java support multiple inheritance?

    1. October 22, 2013 at 8:32 pm | | Reply

      Basically Java does not support multiple inheritance; but supports partially through interfaces.

  2. Lukyamuzi Paul
    October 20, 2013 at 1:09 pm | | Reply

    Create a class called Employee with attributes and another one having a name of your choice which can use the atrributes in the first Employee class

    1. October 20, 2013 at 5:00 pm | | Reply

      So, what you want from me?

  3. Babu
    October 6, 2013 at 1:32 pm | | Reply

    Different between inheritance and polymorphism

    1. October 6, 2013 at 1:53 pm | | Reply

      Dynamic Polymorphism is achieved through inheritance. No inheritance, no dynamic polymorphism.

  4. rambabu
    June 6, 2013 at 2:04 pm | | Reply

    nice understanding subject.lord will help u a lot to do like this concepts.rambabu mca sree vidyanikethan engineering college.

  5. May 16, 2013 at 5:08 pm | | Reply

    Sir why java doesn’t support multiple inheritance through classes what is the problem?

    1. You mean is it compulsory to support for an OOPS language? Two features were kept in mind by the Java designers always – a) to make Java platform-independent (already achieved) and b) to make Java simple to practice. Towards the second goal, they removed goto (which is against a structured programming), pointers, multiple inheritance and introduced implicit garbage collection. Multiple inheritance introduces a confusing concept called virtual functions. To avoid virtual functions menace, they avoided multiple inheritance. Still they are aware of the loss; they support through interfaces. Regarding the simplicity of Java, I can write pages.

  6. jagadish
    May 6, 2013 at 3:34 pm | | Reply

    can u explain in brief with examples and need of upcasting and downcasting of objects in java..


    1. http://way2java.com/casting-operations/object-casting/

      Many places of Java, the methods return the required object as an object of Object class. For example, the get() methods of DS, lookup() method of RMI, in Hibernate and Spring etc, because JRE does not know, exactly what object is to returned until program execution. The JRE converts, for example, Student object into an object of Object class and returns. Now you down cast and use in your program.

      What JRE does internallly:
      Student std1 = new Student();
      Object obj1 = std1;

      Now obj1 is returned. You do the following.

      Student std2 (Student) obj1;

      If you are at Hyderabad, meet me, I will give a better explanation very from the basics.

  7. chennakeshavulu
    February 23, 2013 at 11:28 pm | | Reply

    plz tellme main difference between c and java.

    1. February 24, 2013 at 8:05 am | | Reply

      If you are a C or C++ programmer, you might have found much of the syntax of Java, particularly at the level of operators and statements, to be familiar. Because Java and C are so similar in some ways, it is important for C and C++ programmers to understand where the similarities end. There are a number of important differences between C and Java, which are summarized in the following list:
      No preprocessor
      Java does not include a preprocessor and does not define any analogs of the define, #include, and #ifdef directives. Constant definitions are replaced with static final fields in Java. (refer java.lang.Math.PI field for an example.) Macro definitions are not available in Java, but advanced compiler technology and inlining has made them less useful. Java does not require an #include directive because Java has no header files. Java class files contain both the class API and the class implementation, and the compiler reads API information from class files as necessary. Java lacks any form of conditional compilation, but its cross-platform portability means that this feature is very rarely needed.
      No global variables
      Java defines a very clean namespace. Packages contain classes, classes contain fields and methods, and methods contain local variables. But there are no global variables in Java, and, thus, there is no possibility of namespace collisions among those variables. Global variables are known as instance variables.
      Well-defined primitive type sizes
      All the primitive types in Java have well-defined sizes. In C, the size of short, int, and long types is platform-dependent, which hampers portability.
      No pointers
      Java classes and arrays are reference types, and references to objects and arrays are same as pointers in C. Unlike C pointers, however, references in Java are entirely opaque. There is no way to convert a reference to a primitive type, and a reference cannot be incremented or decremented. There is no address-of operator like &, dereference operator like * or −>, or sizeof operator. Pointers are a notorious source of bugs. Eliminating them simplifies the language and makes Java programs more robust and secure.
      Garbage collection
      The Java Virtual Machine performs garbage collection so that Java programmers do not have to explicitly manage the memory used by all objects and arrays. This feature eliminates another entire category of common bugs and all but eliminates memory leaks from Java programs.
      No goto statement
      Java doesn’t support a goto statement. Use of goto except in certain well-defined circumstances is regarded as poor programming practice. Java adds exception handling and labeled break and continue statements to the flow-control statements offered by C. These are a good substitute for goto.
      Variable declarations anywhere
      C requires local variable declarations to be made at the beginning of a method or block, while Java allows them anywhere in a method or block. Many programmers prefer to keep all their variable declarations grouped together at the top of a method, however.
      Forward references
      The Java compiler is smarter than the C compiler, in that it allows methods to be invoked before they are defined. This eliminates the need to declare functions in a header file before defining them in a program file, as is done in C.
      Method overloading
      Java programs can define multiple methods with the same name, as long as the methods have different parameter lists.
      No struct and union types
      Java doesn’t support C struct and union types. A Java class can be thought of as an enhanced struct, however.
      No enumerated types
      Java doesn’t support the enum keyword used in C to define types that consist of fixed sets of named values. This is surprising for a strongly typed language like Java, but there are ways to simulate this feature with object constants. (Enums introduced from JDK 1.5)
      No bitfields
      Java doesn’t support the (infrequently used) ability of C to specify the number of individual bits occupied by fields of a struct.
      No typedef
      Java doesn’t support the typedef keyword used in C to define aliases for type names. Java’s lack of pointers makes its type-naming scheme simpler and more consistent than C’s, however, so many of the common uses of typedef are not really necessary in Java.
      No method pointers
      C allows you to store the address of a function in a variable and pass this function pointer to other functions. You cannot do this with Java methods, but you can often achieve similar results by passing an object that implements a particular interface. Also, a Java method can be represented and invoked through a java.lang.reflect.Method object.
      No variable-length argument lists
      Java doesn’t allow you to define methods such as C’s printf() that take a variable number of arguments. Method overloading allows you to simulate C varargs functions for simple cases, but there’s no general replacement for this feature.
      Java adds a new right shift operator >>> which inserts zeroes at the top end.
      The + operator scan be used to concatenate strings.
      Java adds another operator instanceof to identify objects.
      Operator overloading is not possible in Java.
      Class definitions take the similar form in Java as in C++, but there is no closing semicolon.
      There is not scope resolution operator :: in Java.
      No destructors in Java
      No templates in Java.
      Inheritance in Java has the same effect an in C++, but the syntax is different.
      Java does not provide direct support for multiple inheritance. We can accomplish
      multiple inheritance by using interfaces.
      All instance variables have default values
      We need not externally define storage for static members like we do in C++.
      A class in Java can have an access specifier to determine whether it is visible outside the file.
      Arrays are quite different in Java. Array boundaries are strictly enforced. Attempting to
      read past the end of an array produces an error.
      One array can be assigned to another in Java.
      Strings in C/C++ are arrays of characters, terminated by a null character. But strings in
      Java are objects.
      Strings can be concatenated with + operator.

      Differences between C and Java in a nutshell
      1. C is a procedural language, Java is object oriented
      2. C’s main structuring element are functions in files. Java organizes code in classes and packages, thereby providing better namespaces.
      3. C code gets compiled into machine code for a specific CPU. Java code gets compiled into bytecode which is interpreted on a virtual machine (JVM). Java code can get compiled into machine code as well (just-in-time compilers etc.)
      4. C does not have exceptions. Errors are handled through return codes.
      5. C types like structures (objects without methods) can be allocated on the stack. Java needs to allocate all non-primitives on the heap using expensive memory management functions (e.g. “new”).
      6. Arrays and strings in C are not bounds-checked. It is the programmers responsibility to stay within the allocated bounds
      7. lets programmers access memory addresses directly through the use of POINTERS. Pointers are variables which contain a memory address. Text (code), data, heap and stack areas are all within a programmers reach. Java lets only the virtual machine access a programs stack, e.g. to perform security checks.
      8. Java primitive types are fixed in length. C types can vary per machine. This lets C take maximum use of hardware specifics (e.g. 16 bit register size vs. 32 bit register size). It also creates portability problems.
      9. C has a preprocessor and include files. The preprocess works like a macro processor which substitutes macros in the program file.

  8. Naveen
    February 21, 2013 at 7:19 pm | | Reply

    Thanks sir, this site is really helpful for fresher . I wanna ask in my system DataInputStream not working and in other system Scanner is not working why? and how can i resolve it. ?

    1. February 22, 2013 at 6:50 am | | Reply

      Scanner works with JDK 1.5 only. Send your DataInputStream code. It must work on all JDKs.

    January 15, 2013 at 11:52 am | | Reply

    diffence between while,do-while,for in java
    loop concept explain

    1. January 19, 2013 at 7:20 pm | | Reply

      It is the same as C/C++.

    January 15, 2013 at 11:45 am | | Reply

    why we use Inheritance ?

    1. January 19, 2013 at 7:23 pm | | Reply

      Straight answer is to call somebody’s method with your class object. Or to say, code reusability.

  11. swathi
    January 4, 2013 at 7:45 am | | Reply

    can u plz give me the answer for return type of constructor?

    1. January 6, 2013 at 1:30 pm | | Reply

      Return type of a constructor is a class object.

      1. manoj
        January 15, 2013 at 11:52 am | | Reply

        what is difference between forloop, dowhileloop,whileloop in java

        1. January 19, 2013 at 7:21 pm | | Reply

          For these simple questions, refer any C/C++ control structures as Java follows the same as that of C/C++.

    2. January 19, 2013 at 7:28 pm | | Reply

      Return type of a constructor is class object.

      1. Rajesh
        March 21, 2013 at 2:47 pm | | Reply

        Then why we don’t write any return type for constructor ?

  12. imran
    November 14, 2012 at 6:12 pm | | Reply

    i was reding inheritance with two books bt cant be able 2 understand,,,,,,later i studied with this site its so easily explained
    thnkxxxxxxxx a lot…

  13. October 19, 2012 at 8:50 am | | Reply

    this is good site of knowladge

    1. October 19, 2012 at 10:21 pm | | Reply

      Nice to hear from you. Advice your friends also to derive the benefit of this web site.

  14. July 8, 2012 at 9:07 am | | Reply

    it is really good website really very useful thanks to this website creator.

  15. Prithu Yadav
    June 12, 2012 at 10:33 pm | | Reply

    Constructor doesn’t have any return type not even void.

  16. Prithu Yadav
    June 12, 2012 at 10:30 pm | | Reply

    Yes we can establish multiple inheritance using interface.

  17. Prithu Yadav
    June 12, 2012 at 10:27 pm | | Reply

    Yes we can overload main() but internally JVM is designed in such a way that it can call only main() of String type i.e public static void main(String[] args)
    class A
    public static void main(String[] args)
    System.out.println(“main() of String type”);

    public static void main(int[] args)
    System.out.println(“main() of Integer type”);

    1. Yes, you understood correctly.

  18. Prithu Yadav
    June 12, 2012 at 10:17 pm | | Reply

    We can create object without using new keyword by using following :-
    2.Reflection API.
    3.Factory Method.

    1. Yes, you are right.

  19. sanjay
    April 12, 2012 at 8:47 am | | Reply

    The java language does not support multiple inheritance.

    1. April 12, 2012 at 12:48 pm | | Reply

      Yes, you are right. But supports through interfaces. Infact, Java proved that an OOP language can exist without the complex multiple inheritance.

  20. Ramesk konda
    February 2, 2012 at 11:03 am | | Reply

    very nice explanation.tanq

  21. January 10, 2012 at 3:01 pm | | Reply

    sir i would be very happy if u give me a chance to work with you wrt to programming and other stuffs……

    1. January 11, 2012 at 10:03 am | | Reply

      OK with pleasure. Send your postings.

  22. January 10, 2012 at 7:21 am | | Reply

    u rocks man …..easy example ..tanx a lot ..:D

  23. December 8, 2011 at 10:18 am | | Reply

    Very best for learning so much simple one.Thanks

  24. November 5, 2011 at 5:38 pm | | Reply

    nice example for inheritance,very helpfull for fresher

    1. November 5, 2011 at 6:13 pm | | Reply

      Thanks. Tell your friends.

  25. October 29, 2011 at 11:28 am | | Reply


  26. October 29, 2011 at 11:28 am | | Reply

    ya…..this is nice…..but one thing is that..have asked 10 questions…
    but could not find answers….
    can i get answers?
    if so,,,will be nice…
    really superb to understand……..
    grade is pictorial representation……really good…..

    1. October 30, 2011 at 6:07 am | | Reply


      The answers will be activated on December 2nd. There is a restriction on publishing the data.

  27. October 11, 2011 at 10:34 pm | | Reply

    Thanks a lot Sir for your fruitful knowledge..

  28. Ashwini
    October 7, 2011 at 5:11 pm | | Reply

    I wish you would have include some more examples…….But by this site its very easy to learn and understand….

  29. arpita mukherjee
    September 28, 2011 at 3:53 pm | | Reply

    very good example and easy to learn

    1. September 28, 2011 at 7:11 pm | | Reply

      Hello Arpita,

      Nice to hear from you. Anything you require more, write me, I will place it. Advise also your friends about this web site.

  30. sadhana
    September 4, 2011 at 11:24 pm | | Reply

    thanks for this

  31. siva
    September 4, 2011 at 2:29 pm | | Reply

    there is multiple inheritance in java

    1. September 4, 2011 at 6:02 pm | | Reply

      Yes, it is mentioned, supports through interfaces..

  32. shubham
    August 29, 2011 at 12:08 am | | Reply

    thankku very nuch

    1. October 19, 2012 at 8:47 am | | Reply

      hello! i am rakesh patel.educational qualification is graduated from mahatmagandhi kashi vidhyapith,varanasi.

      1-what is constructor ,and what are you mean by call of value, call of refrence.

      1. October 19, 2012 at 10:23 pm | | Reply

        Constructor is a Java programming construct called implicitly whenever an object is created. Call-by-reference (or pass-by-reference) and Call-by.value (or pass-by-value) have the same meaning (in Java) as that of C/C++. In Java, pass-by-reference is achieved through object assignment (not by pointers as in C/C++).

  33. August 18, 2011 at 1:47 am | | Reply

    provide more example

  34. siva
    August 12, 2011 at 12:49 pm | | Reply

    This is very good site for inheritance example.
    it is easy to read and understand,detailed explanation

  35. jahir
    August 9, 2011 at 8:09 pm | | Reply

    very nice examples for all programs

    1. S. Nageswara Rao, Sr.Faculty
      August 10, 2011 at 5:51 am | | Reply

      Your comments are encouraging to improve the quality still.

  36. ankit
    July 28, 2011 at 9:37 pm | | Reply

    Good I like this…

  37. pranja
    July 16, 2011 at 12:35 am | | Reply

    This is very good site for inheritance example.
    it is easy to read and understand,detailed explanation

  38. Dominic Muthai Kithuka
    June 7, 2011 at 2:54 pm | | Reply

    your site has most of the recommendable notes: easy to read and understand,detailed explanation and also beautiful colour.I really appreciate your website keep it up and God bless you. (Dominic from Kenya)

    1. S. Nageswara Rao, Sr.Faculty
      June 12, 2011 at 9:11 am | | Reply

      Hello Mr.Kithuka,

      Thanks for your comments. It encourages me to write more and more. You know this site I started only 20 days back working 19 hours per day. This, I feel, still infant state. Your negative comments like what you require and what not found will help me to improve the quality of the site. So, please write.

      Tell your friends are to derive knowledge out of the site.

      Best wishes of the day,
      S.Nageswara Rao
      Author, India.

Leave a Reply