Differentiate between upcasting & downcasting. Explain with reference of classes  (java)?
599192
In the object oriented world of thinking you have objects that are made of classes. These classes can be ordered through a special inheritance relationship into hierarchies of parent/child relationships. \n\nUpcasting means taking a reference to an object and changing\nits type to that of any of its parent classes. (for java, add to this list also all the interfaces that any of the parent classes may be implementing)\n\nFor example:\nclass A extends B{\n}\nclass B{\n}\nclass Program{\n\n    .......\n    B b = new B();\n    A a = (A) b; // this is upcasting!\n    .......\n}\n\nUpcasting in java is implicit. This means that you dont need\nthe preceding parenthesis with the upcasting type.\n    A a = b;\nwould have equally worked. This is because you are going from something specific (class B - child) to something more general (class A - parent) and the java compiler can infer this fact by its design.\n\nDowncasting is the opposite:\n    .......\n    A a = new B(); //here you have an object from class B\n                   //referenced to a variable of class A\n                   //Implicit upcasting happens here.\n\n    B b = (B) a; // this is downcasting.\n\nDowncasting must be explicit. If you try to downcast an\nobject to a type that cant be downcasted to, then the compiler will offer protection by giving you an error.\nOtherwise your program would have crashed at runtime.\n\nYou can test with the operator instanceOf whether a \ndowncast is safe.\nexample:\n   if (a instanceOf (B)) { \n        b = (B)a;\n   }\n\nThe problem with this is that it creates a dependency in that segment of code and the type B. If in the future you create sibling to B classes you will have to remember to change all the places where you are checking with "instanceOf" and this can be a try nightmare on a large system.\n\nSo, generally speaking, you want to create code that avoids downcasting. This is not always possible and not always a good idea as there are many cases where explicit downcasting is needed or at least is possible to use without problems. \nAgain generally speaking, you want to create designs that have parts that are as independent, decoupled, reusable, robust, modular, and change adaptive as possible. This is not easy because many of these forces lead you to contradictions. So its all about making choices.\n\nfor an easy visual guide to java have a look at an online tutorial that I have recently added to: http://www.thanassis.com/java/index.htm
903318
Both have almost the same effect.\n\nbut it mostly depends on how efficient val.getName() works.\nbut if you using the same method to fetch the value and use it as a parameter,the first one would be better it will at least save a couple of object creations.
52791
C) ABC, somthing1, something2 must be interface for the expression to be legal.\n\nThough java doesn't supports multiple inheritence for class, an interface can extend as many interface as needed. You can try compiling. But there is also a reason behind it.\nJava does not supports multiple inheritence because in diamond inheritence ( B and C extends A and D extends both B and C) it can cause ambiguity( as two copies of members of A would present in D).\nThis is not so for interface as there can't be ambiguity as all refer to same copy. So Java supports multiple inheritence for Inetrface
800373
Inheritance means you are making the child, aggregation is you are inlcuding it inside. \nconsider \nclass A\n{\n}\n\nclass B :: class A\n{\n}\n\nThis is inheritance. class N has inherited properties from class A.\n\nwhile,\n\nclass B\n{\n  class A classa;\n}\n\nThis is aggregation as class A is now included in class B.
528997
Operator overloading is just “syntactic sugar,” which means it is simply another way for you to make a function call.\n\n\nThe difference is that the arguments for this function don’t appear inside parentheses, but instead they surround or are next to characters you’ve always thought of as immutable operators.\n\n\nThere are two differences between the use of an operator and an ordinary function call. The syntax is different; an operator is often “called” by placing it between or sometimes after the arguments. The second difference is that the compiler determines which “function” to call. For instance, if you are using the operator + with floating-point arguments, the compiler “calls” the function to perform floating-point addition (this “call” is typically the act of inserting in-line code, or a floating-point-processor instruction). If you use operator + with a floating-point number and an integer, the compiler “calls” a special function to turn the int into a float, and then “calls” the floating-point addition code.
419452
what does intercast mean? Sorry i did not understand the question.
737577
public  abstract class   Animal {\n\nprivate String description;\nprivate float height;\nprivate float weight;\n\n//\n\ngetter and setter methods\n//\n\n}\n\npublic class Bird extends Animal{\nprivate float wingspan;\n\n//\n\ngetter and setter methods\n//\n\npublic Bird(String des,cloat h, float w , float s){\n\nthis.height =h;\nthis.width =w;\nthis.span =s;\n\n}\n\n}\n\nI don't have the the time  finish this...\n\nGood luck
193431
Probably because the constructor doesn't accept objects as arguments. Just a guess, though.
1131033
The first is a Java Class called Main.\n\nThe second is the constructor for this class. This is what isused to basically set the class up and make an instance of it.\n\nThe third is a method called main which takes in a string array which you have named args. You could call args whatever you want, its juts a general name most coders put on it. It has a modifier which is static and is public so other classes can invoke it. The main method is what is looked for by the java compiler at run time when you execute the program.\nSo a class may look like this:\n\npublic class Main\n{\npublic String greeting;\n\n public Main()\n{\ngreeting = "hello"\n}\n\npublic static void main(String[] args)\n{\nSystem.out.println(args[0]);\nSystem.out.println(greeting);\n}\n}\n\nThis would result in the value stored at args[0] being printed out. Then "hello" printed out on a new line.\nThe args are the arguments that you pass to your program. Most programs take in strings or ints.
1147478
Memory Handling.\nWhatever memory space you occupy by instantiating the objects should be released after your use.\nType Casting should also be taken care.
265933
Object is an instance of a class.\n\nConstructor is a also a method which only gets called when an object is instantiated.  (ex. Myclass a = new Myclass)\n\nMethod is a new term for function.  You may write lines of codes inside of a method, and reuse it everytime(OO design)\n\nclass MyClass\n{\n   MyClass() // constructor\n   int AddNumber(int a, int b);  // method AddNumber returns a+b\n}\n\nmain\n{\n  Myclass myObject = new MyClass();  // myObject is an object\n  int sum = myObject.AddNumber(1,2); // 1 + 2 = 3\n  return 0;\n}\n\n\nHope that helps!!! Go java
1080797
Invoking Object's clone method on an instance that does not implement the Cloneable interface results in the exception CloneNotSupportedException being thrown.\n\nBy convention, classes that implement this interface should override Object.clone (which is protected) with a public method. See Object.clone() for details on overriding this method.\n\nNote that this interface does not contain the clone method. Therefore, it is not possible to clone an object merely by virtue of the fact that it implements this interface. Even if the clone method is invoked reflectively, there is no guarantee that it will succeed. \n\nThat means you cannot simply say implements Cloneable since Cloneable has absolutely no methods. Especially not clone. The Object Interface does have clone. Which has the structure of: protected Object clone() throws CloneNotSupportedException\n\nAs the docs say:\nThe class Object does not itself implement the interface Cloneable, so calling the clone method on an object whose class is Object will result in throwing an exception at run time.
23160
I assume that you're talking about object-oriented languages here.\n\nYou want to define a base class when there is specific functionality that can be implemented, and should be generally available to all subclasses.\n\nAn interface is simply a specification of available functions and data fields, with no actual code attached. You would define one where you need to specify a black box to fit in a system, but aren't implementing any of the actual working pieces for the black box.
35366
Java provides the StringBuffer and String classes, and the String class is used to manipulate character strings that cannot be changed. Simply stated, objects of type String are read only and immutable. The StringBuffer class is used to represent characters that can be modified.\n\nThe significant performance difference between these two classes is that StringBuffer is faster than String when performing simple concatenations. In String manipulation code, character strings are routinely concatenated. Using the String class, concatenations are typically performed as follows:\n\n\n     String str = new String ("Stanford  ");\n     str += "Lost!!";\n\nIf you were to use StringBuffer to perform the same concatenation, you would need code that looks like this:\n\n\n     StringBuffer str = new StringBuffer ("Stanford ");\n     str.append("Lost!!");\n\nDevelopers usually assume that the first example above is more efficient because they think that the second example, which uses the append method for concatenation, is more costly than the first example, which uses the + operator to concatenate two String objects.\n\nThe + operator appears innocent, but the code generated produces some surprises. Using a StringBuffer for concatenation can in fact produce code that is significantly faster than using a String. To discover why this is the case, we must examine the generated bytecode from our two examples. The bytecode for the example using String looks like this:\n\n\n0 new #7 <Class java.lang.String>\n3 dup\n4 ldc #2 <String "Stanford ">\n6 invokespecial #12 <Method java.lang.String(java.lang.String)>\n9 astore_1\n10 new #8 <Class java.lang.StringBuffer>\n13 dup\n14 aload_1\n15 invokestatic #23 <Method java.lang.String valueOf(java.lang.Object)>\n18 invokespecial #13\n21 ldc #1 <String "Lost!!">\n23 invokevirtual #15 <Method java.lang.StringBuffer append(java.lang.String)>\n26 invokevirtual #22 <Method java.lang.String toString()>\n29 astore_1\n\nThe bytecode at locations 0 through 9 is executed for the first line of code, namely:\n\n\n     String str = new String("Stanford ");\n\nThen, the bytecode at location 10 through 29 is executed for the concatenation:\n\n\n     str += "Lost!!";\n\nThings get interesting here. The bytecode generated for the concatenation creates a StringBuffer object, then invokes its append method: the temporary StringBuffer object is created at location 10, and its append method is called at location 23. Because the String class is immutable, a StringBuffer must be used for concatenation.\n\nAfter the concatenation is performed on the StringBuffer object, it must be converted back into a String. This is done with the call to the toString method at location 26. This method creates a new String object from the temporary StringBuffer object. The creation of this temporary StringBuffer object and its subsequent conversion back into a String object are very expensive.\n\nIn summary, the two lines of code above result in the creation of three objects:\n\n   1. A String object at location 0\n   2. A StringBuffer object at location 10\n   3. A String object at location 26\n\nNow, let's look at the bytecode generated for the example using StringBuffer:\n\n\n0 new #8 <Class java.lang.StringBuffer>\n3 dup\n4 ldc #2 <String "Stanford ">\n6 invokespecial #13 <Method java.lang.StringBuffer(java.lang.String)>\n9 astore_1\n10 aload_1\n11 ldc #1 <String "Lost!!">\n13 invokevirtual #15 <Method java.lang.StringBuffer append(java.lang.String)>\n16 pop\n\nThe bytecode at locations 0 to 9 is executed for the first line of code:\n\n\n     StringBuffer str = new StringBuffer("Stanford ");\n\nThe bytecode at location 10 to 16 is then executed for the concatenation:\n\n\n     str.append("Lost!!");\n\nNotice that, as is the case in the first
382095
java usees wrapper classes...Byte,Integer..they are in java.lang package..\n\nin each such class there is one memeber \nstatic int SIZE\n\nusing that u can find out..\n\neg.System.out.println(Byte.SIZE);\n//The number of bits used to represent a byte value in two's complement binary form\n\nSIMILARITY FOR OTHER DATA TYPES..\n\ncheck out documentation site..or if u have already downloaded doc..then use that..
160381
Obviously the idea behind multiple inheritance is to\nallow objects to have the behaviors of multiple types.\nHowever, how often have you actually been able to\ninherit the *behavior* (ie. the implementation) from\nmultiple parent types, as opposed to just the *interface*?\n\nIn some cases, you can get the semantics you want by\nincluding on object of one of the parent types.  And\nwhen appropriate, Java allows you to implement an\ninterface for another "parent" type without even pretending\nthat you could inherit the implementation.  \n\nAs for why Java never had multiple inheritance, in my\nopinion, it is confusing and error prone.
329175
I'm assuming your accessing it from another class? \n\nPrivate declaration stops this from occuring. You need to provide a public property ie.\n\nprivate _str as string = ""\nPublic Property etc as string\nGet\nreturn _str\nEnd Get\nSet(value as string)\n_str = value\nEnd Set\nEnd Property\n\nOtherwise if you are accessing a class-scope variable normally, you could do:-\n\nPublic class Class1\n Private Str as string = ""\n Private Sub New()\n   Str = "Hehehe"\n End Sub\nEnd Class\n\nQuestion wasn't clearly stated, but i think that should answer it...