What are the alternatives to inheritance?

Delegation is an alternative to inheritance. Delegation denotes that you include an instance of any class as an instance variable, and forward messages to the instance. It is safer than inheritance because it ceases you to think about forwarded message , because the instance is of a known class, rather than a new class, and … Read more

How can a collection object be sorted?

// Sort Collections.sort(list); // Sort case-insensitive Collections.sort(list, String.CASE_INSENSITIVE_ORDER); // SortReverse-order Collections.sort(list, Collections.reverseOrder ()); // Reverse-order sort case-insensitive Define local, member and a class variable. Within a method variables declared are called “local” variables. Variables declared in the class i.e not in any methods are “member” variables (global variables). Variables declared in the class i.e not … Read more

Why is explicit object casting needed?

  In order to assign a superclass object in a variable to a subclass,one needs to do explicit casting. For example:Person person=null; Man man = (Man)person; An automatic casting takes place when we typecast a object in subclass as parent class object. Define Externalizable. Externalizable is coined as an Interface It extends the Serializable Interface. … Read more

Can an inner class be built in an Interface?

Yes,an inner class may be built an Interface. public interface xyz { static int p=0; void m(); class c { c() { int q; System.out.println(“inside”); } public static void main(String c[]) { System.out.println(“inside “); } }; }   In Java, as of my last knowledge update in January 2022, an inner class can be defined … Read more

What is the difference between UNION and UNION ALL?

This deals with SQL. UNION only selects distinct values, UNION ALL selects all values. In the context of Core Java, the terms UNION and UNION ALL are not directly related. Instead, they are typically associated with SQL (Structured Query Language), which is used for database operations. In SQL: UNION: The UNION operator is used to combine … Read more