Java Tutorial - 3 | Edureka

preview_player
Показать описание
Take instructor-led Live class on Java Tutorial at :

The following topics were covered in this Java Tutorial:

The overloaded function must differ either by the number of arguments or operands or data types but with same name. So we are trying use same method name to perform different functions.
Method overriding:
The implementation in the sub class overrides (replaces) the implementation in the super class. It is done by providing a method that has same name, same type of parameters and same return type of method. So in method overriding the method signature will remain same.
Super keyword is used to call the method or variable in the parent class. Super keyword works only when there exists inheritance between them.
In both the method overloading and method overriding we are trying to use same method for different functionalities i.e method is acting in multiple forms which is nothing but polymorphism(acting in multiple forms) , an OOP concept.
If a method is declared final then that method cannot be overridden. The final keyword can also used for class. If we declare a class as final then that class cannot be inherited.
Abstract Class:
Abstraction is nothing but hiding. That means you do not provide the detail. You don't get to know what is inside that but just have an overview on that and that's called abstraction (data hiding).
Real world example of abstraction is: you drive a car; you know that car moves on four wheels and many things. You don't know the details about how it works inside. You don't know the internal details of how the car will move left when you move your steering left.
In java you can create classes that provide overview but the definition is not present. Suppose you have class shape, you don't know have the details whether the shape is Triangle or Circle or Rectangle and so on. So making the class shape as abstract which gives overview that it is some kind of shape.
What is an Abstract Class?
An abstract class is a class preceded by "abstract" keywords. It may or may not use abstract methods. E.g.: abstract class Shape {..................}
What is Abstract method?
A method that is preceded by "abstract" keyword and without any implementation for it. E.g.: abstract void add(int x, int y);
In java we create an abstract class and put the details into that just the names i.e abstract methods. Finally what we do is create a class that extends abstract class and give the implementation for the details of abstract class methods.
What is the difference between inheritance and Abstract class?
Inheritance is one of the OOP's concepts that extend a class. Abstract means you are actually having an abstract class and an abstract method of that class. Inheritance do not tell you whether the class is abstract or not. Inheritance is an OOP's concept and Abstraction is another OOP's concept. In abstraction we use the concept of inheritance. Abstract methods will be present in interfaces and abstract class.
The abstract methods present in abstract class have to be implemented in the class which extends the abstract class. It is mandatory to implement all the abstract methods in the class that extends abstract class.

Interface:
Interfaces are declared using the "interface" keyword. You consider interface as a medium through which you can use certain methods which do not have an implementation.
Interface can contain method signature i.e abstract methods with no implementation and constant declarations i.e variable declarations that are declared have to be both static and final. We use "interface" keyword to create an interface. If a class want to use an interface then the class should use "implement" keyword to get the interface and implement all the abstract methods present in an interface compulsorily.
What is the difference between interface and abstract class?
An interface contains only abstract methods where as an abstract class contains both abstract methods and well-defined methods.
What is the advantage of an interface?
We know that java does not support multiple inheritance but it can be achieved with the help of interface. A class can extend only one class where as a class can implement any number of interfaces.

Рекомендации по теме
join shbcf.ru