UrbanPro

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Base obj=new Child(); What are the advantage and real life application of above code?

Asked by Last Modified  

25 Answers

Learn Java

Follow 1
Answer

Please enter your answer

Java Trainer

Have you ever observed while communicating with databases? You can find such type of example while writing code from communicating with DB. Connection connectionObject = DriverManager.getConnection(); or Statement simpleStatement = connectionObject.getStatement(); The value of the connectionObject...
read more
Have you ever observed while communicating with databases? You can find such type of example while writing code from communicating with DB. Connection connectionObject = DriverManager.getConnection(); or Statement simpleStatement = connectionObject.getStatement(); The value of the connectionObject variable depends on the database driver you are using (most of the time you load the driver with Class.forName("some driver implementaion")). The answer for your question is, such type of coding helps you to implement and use your own mechanism that suits to your requirements / circumstances. read less
Comments

Tutor

1.It is basis of Polymorphism. 2. Lets say you have a parent class called Animal and child classes called Dog, Cat, and Lizard. Each class has a method call makeSound(). Then when you say Animal a1 = new Dog(); and Animal a2 = new Cat(), a1.makeSound() will bark and a2.makeSound() will meow. The...
read more
1.It is basis of Polymorphism. 2. Lets say you have a parent class called Animal and child classes called Dog, Cat, and Lizard. Each class has a method call makeSound(). Then when you say Animal a1 = new Dog(); and Animal a2 = new Cat(), a1.makeSound() will bark and a2.makeSound() will meow. The technical term for this behavior is called polymorphism. It is useful for code reuse. You only need to write code once for an application that has Animals makeSound() when they are happy, instead of separate code for each animal type. 3.Another use of polymorphism is hiding your code's implementation from other users. For example you can show other users that you are using a List and then you have the choice to implement the List as a LinkedList or as an ArrayList. You can also choose a LinkedList and then at a later time switch to an ArrayList without effecting your users. You also can't say Dog d = new Animal() because a Dog is an Animal but an Animal is not necessarily a Dog. read less
Comments

Industry expert and professional lecturer/trainer

Dynamic Polymorphism which promotes calling only those methods which parent is aware of. Mostly used in API creation.
Comments

You can get all the attributes and behavior of a class by creating its object.
Comments

Best Training institute for Both Technical and Non Technical domians

This is the most fundamental use of polymorphism because using a parent class reference to refer to a child object is what allows you to take advantage of the benefits of polymorphism. Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs...
read more
This is the most fundamental use of polymorphism because using a parent class reference to refer to a child object is what allows you to take advantage of the benefits of polymorphism. Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. read less
Comments

Software Professional Trainer with 26+ years of Experience in Software Design and Development

It dynamic polymorphism, where derived class object is assigned to Base class object. Whenever you want to do late binding you can use this concept.
Comments

Software Professional with 14 years experience - Mentoring & Training Students & Professionals

Polymorphishm is the advantage of the above code. Say you have animal class with animal reference you can create object of a cat or a dog. So in run time it differentiates. For example Animal a = new Cat(); (if cat extends animal) a = new Dog()(if dog extends animal) so same reference a can hold objects...
read more
Polymorphishm is the advantage of the above code. Say you have animal class with animal reference you can create object of a cat or a dog. So in run time it differentiates. For example Animal a = new Cat(); (if cat extends animal) a = new Dog()(if dog extends animal) so same reference a can hold objects of cat and dog as both inherites animal read less
Comments

Let's simplify Coding, It's a great Fun.

Hi, The above code is using the parent reference type to point to child object. Now from the obj reference you can point to all the members of base class as well as to the child class (by type casting). This is the normal practice in java technologies to create the parent reference type for child...
read more
Hi, The above code is using the parent reference type to point to child object. Now from the obj reference you can point to all the members of base class as well as to the child class (by type casting). This is the normal practice in java technologies to create the parent reference type for child objects, this strategy enables your code flexible for any sub-child, for example, if you have a method like this add(Collection c), this means parameter can be object of List,Set or any sub-collection object, this makes your method more generic & powerful. regards vijay read less
Comments

This is the basis for polymorphism: Imagine you have several child classes that inherit from you parent class. You want to use all these child classes through the interface / methods defined on your parent class, without worrying about the implementation details in each child class (each might do something...
read more
This is the basis for polymorphism: Imagine you have several child classes that inherit from you parent class. You want to use all these child classes through the interface / methods defined on your parent class, without worrying about the implementation details in each child class (each might do something different, but with the same overall semantics). This is possible because the child class has a IS A relationship with its parent class since child inherits from parent. read less
Comments

Java/J2EE/SFDC Corporate Trainer

This is actually dynamic binding, depending upon demand the memory will be created for respective object.
Comments

View 23 more Answers

Related Questions

What are the differences between Class Methods and Instance Methods in Java?
Class methods are static methods in java. The method can be called without creating an instance of the class.For e.g, main method is declared static that is why we are able to call main method without...
Neval
0 0
5
I am mechanical student. Can you please tell me opportunities in software field?
Yes, you can get an opportunity. I have seen many mechanical, chemical and biotechnology students are working in its sector. For that, you have to learn some IT courses.
Sainathgowd
Why Operator Overloading in not allowed in JAVA?
Java does not support operator overloading by programmers. This is not the same as stating that Java does not need operator overloading. Operator overloading is syntactic sugar to express an operation...
Ashish
Is it really needed to do Java training before graduation, to get a job?
Yes, It's must to get better opportunities and to standard alone in IT field. Not only core Java but also learn Spring,Hinernat ,Struts. ANGULARJS add an advantage to get job easily.
Udaybhan
Is Java a compiler or Interpreter?
Java is a programming language and computing platform first released by Sun Microsystems in 1995. A Java compiler is a compiler for the Java programming language. A JVM interprets bytecode and...
Dr Rakesh

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

CoreJAVA
Core Java Training High Level Course Content Trained by Java Architect 1. Core Java Programming Introduction of Java 2. Data types and Operators 3. Control Flow statements 4. OOPS and its application...
A

Java Training Syllabus
Learn JAVA-J2EE Syllabus Core Java - Syllabus aligned to OCA Exam - JDK 8 Object-Oriented Programming (OOPS) concepts: Programming Languages Object Oriented Programming Classes & Objects Pillars...

Example of DependsOnMethod in TestNG
public class dependsonM { @Test public void login() { System.out.println("login"); } @Test (dependsOnMethods = {"login"}) public void email() { //Intentionally I am failing this testcase Assert.assertTrue(false);...
S

Sarthak C.

0 0
0

Advance Java
1) Servlet • Basics of Servlet • Servlet Request • Servlet Collaboration • Servlet Config • Servlet Context • Attribute • Session Tracking • Event and Listener •...
A

Observer Pattern in Java.
As I was going through the different source code files of the Java Util package, I found the implementation of the Observer Pattern ( see the Gang of Four books for more information on this pattern) in...

Recommended Articles

Designed in a flexible and user-friendly demeanor, Java is the most commonly used programming language for the creation of web applications and platform. It allows developers to “write once, run anywhere” (WORA). It is general-purpose, a high-level programming language developed by Sun Microsystem. Initially known as an...

Read full article >

Java is the most famous programming language till date. 20 years is a big time for any programming language to survive and gain strength. Java has been proved to be one of the most reliable programming languages for networked computers. source:techcentral.com Java was developed to pertain over the Internet. Over...

Read full article >

Before we start on the importance of learning JavaScript, let’s start with a short introduction on the topic. JavaScript is the most popular programming language in the world, precisely it is the language - for Computers, the Web, Servers, Smart Phone, Laptops, Mobiles, Tablets and more. And if you are a beginner or planning...

Read full article >

Java is the most commonly used popular programming language for the creation of web applications and platform today. Integrated Cloud Applications and Platform Services Oracle says, “Java developers worldwide has over 9 million and runs approximately 3 billion mobile phones”.  Right from its first implication as java 1.0...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more