Question

Ob ad

Please provide definition, explanation and examples for each topic.
Thanks

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Class

A class is an entity that determines how an object will behave and what the object will contain. In other words,
it is a blueprint or a set of instruction to build a specific type of object. also a class is a template definition of the method s and variable s in a particular kind of object . Thus, an object is a specific instance of a class; it contains real values instead of variables.

The class is one of the defining ideas of object-oriented programming. Among the important ideas about classes are:

  • A class can have subclasses that can inherit all or some of the characteristics of the class. In relation to each subclass, the class becomes the superclass.
  • Subclasses can also define their own methods and variables that are not part of their superclass.
  • The structure of a class and its subclasses is called the class hierarchy.

Syntax

class <class_name>{  
field;  
method;  
}  

Objects

An object is nothing but a self-contained component which consists of methods and properties to make a particular type of data useful. Object determines the behavior of the class. When you send a message to an object, you are asking the object to invoke or execute one of its methods.an object can be a variable, a data structure, a function, or a method, and as such, is a value in memory referenced by an identifier.

In the class-based object-oriented programming paradigm, object refers to a particular instance of a class, where the object can be a combination of variables, functions, and data structures.

From a programming point of view, an object can be a data structure, a variable or a function. It has a memory location
allocated. The object is designed as class hierarchies.

Syntax

ClassName ReferenceVariable = new ClassName();

Inherintance

Inheritance is a mechanism in which one class acquires the property of another class. For example, a child inherits the traits of his/her parents. With inheritance, we can reuse the fields and methods of the existing class. Hence, inheritance facilitates Reusability and is an important concept of OOPs.

Types of Inheritance
There are Various types of inheritance in Java:
Single Inheritance:
In Single Inheritance one class extends another class (one class only).

TF S S 8 9 10 11 5 16 17 18 2 23 24 25 9 30 31 FEBRUARY SUNDAY

In above diagram, Class B extends only Class A. Class A is a super class and Class B is a Sub-class.

Multiple Inheritance:
In Multiple Inheritance, one class extending more than one class. Java does not support multiple inheritance.

As per above diagram, Class C extends Class A and Class B both.

Multilevel Inheritance:
In Multilevel Inheritance, one class can inherit from a derived class. Hence, the derived class becomes the base class for the new class.

As per shown in diagram Class C is subclass of B and B is a of subclass Class A.

Hierarchical Inheritance:
In Hierarchical Inheritance, one class is inherited by many sub classes.

As per above example, Class B, C, and D inherit the same class A.

Hybrid Inheritance:
Hybrid inheritance is a combination of Single and Multiple inheritance.

As per above example, all the public and protected members of Class A are inherited into Class D, first via Class B and secondly via Class C.
example
class Doctor {
void Doctor_Details() {
System.out.println("Doctor Details...");
}
}

class Surgeon extends Doctor {
void Surgeon_Details() {
System.out.println("Surgen Detail...");
}
}

public class Hospital {
public static void main(String args[]) {
Surgeon s = new Surgeon();
s.Doctor_Details();
s.Surgeon_Details();
}
}

here our parent class is Doctor and child class id Surgen thar extends from the Doctor

Polymorphism

Polymorphism is an object-oriented programming concept that refers to the ability of a variable, function or object to take on multiple forms. A language that features polymorphism allows developers to program in the general rather than program in the specific.

In a programming language that exhibits polymorphism, objects of classes belonging to the same hierarchical tree (inherited from a common base class) may possess functions bearing the same name, but each having different behaviors.

As an example, assume there is a base class named Animals from which the subclasses Horse, Fish and Bird are derived. Also assume that the Animals class has a function named Move, which is inherited by all subclasses mentioned. With polymorphism, each subclass may have its own way of implementing the function. So, for example, when the Move function is called in an object of the Horse class, the function might respond by displaying trotting on the screen. On the other hand, when the same function is called in an object of the Fish class, swimming might be displayed on the screen. In the case of a Bird object, it may be flying.

Overriding

In any object-oriented programming language, Overriding is a feature that allows a subclass or child class to provide a specific implementation of a
method that is already provided by one of its super-classes or parent classes. When a method in a subclass has the same name, same parameters or signature
and same return type(or sub-type) as a method in its super-class, then the method in the subclass is said to override the method in the super-class.

Method overriding is one of the way by which java achieve Run Time Polymorphism.The version of a method that is executed will be determined by the object that is used to invoke it. If an object of a parent class is used to invoke the method, then the version in the parent class will be executed, but if an object of the subclass is used to invoke the method, then the version in the child class will be executed.In other words, it is the type of the object being referred to (not the type of the reference variable) that determines which version of an overridden method will be executed.

Overloading
Overloading refers to the ability to use a single identifier to define multiple methods of a class that differ in their input and output parameters.
Overloaded methods are generally used when they conceptually execute the same task but with a slightly different set of parameters.

If you have any query regarding the answer please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appriciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Please provide definition, explanation and examples for each topic. Thanks Ob ad
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT