Can we use multiple extends of class in java selenium? [duplicate] - java

This question already has answers here:
Java Multiple Inheritance
(17 answers)
Closed 2 years ago.
Please explain how to extend two classes from different packages.
public class Animal extends Herbivores extends Omnivores {
}

Multiple Inheritance or Diamond Inheritance is a feature of object oriented concept, where a class can inherit properties of more than one parent class.
Java does not support that.
There are multiple resources over the net which tells you the problem that arises if you are allowed to do that.
Coming to your problem, it seems to me like a fault in Design.
Animal should be a parent type rather than a child type. Both Herbivores and Omnivores are animals. Whereas an animal doen't necessary have to be either. It can be a carnivore also.

Related

gwt interface HostedModeOptions extends more than 1 class [duplicate]

This question already has answers here:
Can an interface extend multiple interfaces in Java?
(7 answers)
Closed 5 years ago.
i work in GWT. The Devmode class in gwt has an interface in it called 'HostedModeOptions'. But HostedModeOptions extends more than 1 class like :
protected interface HostedModeOptions extends HostedModeBaseOptions, CompilerOptions {
ServletContainerLauncher getServletContainerLauncher();
String getServletContainerLauncherArgs();
void setServletContainerLauncher(ServletContainerLauncher scl);
void setServletContainerLauncherArgs(String args);
}
How is this possible in java 7 ? As far as i know we cannot extend more than 1 class at a time in java 7.
Can anyone explain please .
You cannot extend other more than one class however you can implement many interfaces. If you are developing an interfacing you can make use of other interface and can extend many other interfaces.
They are all interfaces and not classes.. An interface can extends many interfaces. This facility is there from very first version of Java.
If you have any doubts regarding ambiguity, below link might help a bit
Can an interface extend multiple interfaces in Java?

Why java does not support multiple inheritance? [duplicate]

This question already has answers here:
Why is there no multiple inheritance in Java, but implementing multiple interfaces is allowed?
(21 answers)
Closed 7 years ago.
In java by default all classes are inherit from Object class and even we can also inherit the classes.
class A{ // default **Object class** is extended
}
class B extends A{
//default **Object class** is extended and also **class A** extended.
}
Then why we say that java doesn't support multiple inheritance through classes?
It is just to remove ambiguity, because multiple inheritance can cause
ambiguity in few scenarios. One of the most common scenario is Diamond
problem.
Look at this page : http://www.instanceofjava.com/2014/12/why-java-does-not-supports-multiple.html

Java - Extending Unknown Classes [duplicate]

This question already has answers here:
Extend a generic type in Java
(2 answers)
Closed 8 years ago.
I wanted to create a class that can extend an unknown class that is provided at runtime. I thought that I could do something like this:
public class Foo<T extends Bar> extends T {}
but that doesn't work. Is there a way to do this?
Not without some crazy runtime code generation. Java's generics are not the same sort of thing as C++'s templates: Internally, T is simply treated as an Object, and up- and down-casted as necessary for the benefit of your code. So while a C++ template is instantiated for a particular T, and can decide at compile-time whether that works, in Java the machinery underlying inheritance requires that the actual base class be decided upon in the class definition itself.

why we are declaring class as abstract even if it has no abstract methods [duplicate]

This question already has answers here:
Defining an abstract class without any abstract methods
(12 answers)
Use of an abstract class without any abstract methods
(7 answers)
Closed 9 years ago.
can any one please explain the scenario when A class may be declared abstract even if it has no abstract methods. i have tried in many websites but i did not found it.Thanks a lot.
Broadly, this would be because the class provides concrete implementations of functionality but should not itself be instantiated. For example, an AbstractWidget in a price calculator may not be suitable to directly instantiate, but it has concrete implementations of certain widget functionality like being rearranged. The expectation is that the subclass adds new methods altogether, or overrides the ones already declared.

When to use an abstract class? An interface? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Interface vs Abstract Class (general OO)
I am little bit familiar with the terms Abstract class and the interface.
But i want to know in which situation i have to use the interface and in which condition the abstract class.
Thanks
Interface vs Abstract Class should be a useful read.
In short, Abstract Classes are meant to be extended, as in you're giving someone a base to work off of. Interfaces ensure that things have a common way of interacting with one another without having to worry about the inside details.
Simple answer: you can implements many interfaces, but can only inherit from one class, so if you want to inherit some logic, you should use Abstract Class, otherwise Interface is more extensible.

Categories