Java Classes

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Interfaces are useful for:

1- Declaring methods that one or more classes are expected to implement. 2- Capturing similarities between unrelated classes without forcing a class relationship. 3- Determining an object's programming interface without revealing the actual body of the class.

Q: Explain the difference between function overloading and overriding?

1- Overloading talks about the relationship between methods of the same class whereas the overriding focuses on the relationship between a superclass method and subclass method. 2- Overloading doesn't impact the inheritance from the superclass whereas the overriding impedes inheritance from the superclass. 3- In overloading, you have different methods sharing the same name whereas in overriding, the methods in subclasses replace the superclass versions. 4- Overloading requires the methods to be implemented with distinct signatures whereas overriding limits to use the same markup.

Q: Describe the difference between a Sub-Class and an Inner Class?

A subclass is a class which gets inherited from another class termed as super class. It can easily access all public/protected methods and fields of its superclass. Inner class is a class which gets cradled within another class. An Inner class can access all variables and methods provided by the outer class.

More on interface

An interface by definition has all public members without any implementation. While an abstract class may group different flavors of class members like private, protected, etc. but has at least one abstract method.

Q: What difference you see between an Abstract class and an Interface?

An interface by definition has all public members without any implementation. While an abstract class may group different flavors of class members like private, protected, etc. but has at least one abstract method.

Q: What is an interface and why is it used?

An interface is similar to a class which may contain method's signature only but not bodies, and it is a formal set of method and constant declarations that must be defined by the class that implements it.

More on abstract

Every abstract class must provide an instance method that defines its default behavior. While in an Interface, only the declaration of constants and instance methods is permissible, you can't implement the default behavior, and all methods are abstract by default.

Q: What do you know about anonymous and inner classes?

Inner class- are the ones having their definition within other classes, including those defined in methods. These can assume any accessibility including private, public, etc. Anonymous class- It is a class which has its definition inside a method with no name. You can instantiate or declare it in the same place, and it doesn't support explicit constructors.

Q: Are there any performance implications of Interfaces over abstract classes, if yes then specify?

Interfaces require additional indirections to find methods in the implementing class. This behavior makes them slower than abstract classes. Another fact that a QA engineer should know that a class can only extend a single abstract class whereas it can implement multiple interfaces. Also with interfaces, one has to address all of its methods which lead to extra efforts while developing an automation framework.

Q: What is an abstract class and why is it used?

The abstract class serves as a template, and you can't instantiate it. It may contain static data, and you've to extend it to make it functional. Also, you must note that any class which has an abstract method automatically turns itself abstract.

Q: What if you declare a class w/o any access modifiers, where can you use this class in your program?

When we don't specify any access modifier for a class, then Java assign package level access to it. It implies that you can access such a class from other classes and interfaces within the boundary of that package.

Q: How would you describe the difference between this() and super()?

You can use this() for invoking the constructor of the class while super() helps to call the super class constructor.

Q: What difference you see between superclass and subclass?

You can use this() for invoking the constructor of the class while super() helps to call the super class constructor.


Ensembles d'études connexes

Medical Terminology Ch1 Test Questions

View Set

General Insurance Regulation Chapter Quiz

View Set

Describe the components and digestive functions of saliva.

View Set

Financial Management - Chapter 7

View Set

GI - Gastric Secretion and Hyperacidity Workshop

View Set

Ch. 7 Microbiology Assignment Questions

View Set