This document discusses abstract classes and interfaces in Java. It provides examples of abstract classes that cannot be instantiated but can be extended by subclasses. Interfaces are defined as collections of method signatures without implementations that classes can implement to define common behaviors. The document compares abstract classes and interfaces, and provides examples of defining and implementing interfaces. It also discusses abstract and final methods, and the use of abstract classes and interfaces in Java applications.
What are Abstract Classes in Java | EdurekaEdureka!
YouTube Link: https://youtu.be/5X0Y--92pMI
**Java, J2EE & SOA Certification Training - https://www.edureka.co/java-j2ee-training-course **
This Edureka PPT on Abstract Classes in Java will provide you with detailed knowledge about Abstract Classes in Java and along with it, This PPT will also cover some examples of Abstract Classes in Java, in order to provide you with a deep understanding about their functionality. This PPT will cover the following topics:
What are Abstract Classes in Java?
Why do we need an Abstract Classes in Java?
Rules for using Abstract Classes in Java
Ways to achieve Abstraction in Java
The Syntax for Abstract Classes
Practical Examples of Abstract Classes
Difference between Interface and Abstract Class
Complete Java Playlist: http://bit.ly/2XcYNH5
Complete Blog Series: http://bit.ly/2YoabkT
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
What are Abstract Classes in Java | EdurekaEdureka!
YouTube Link: https://youtu.be/5X0Y--92pMI
**Java, J2EE & SOA Certification Training - https://www.edureka.co/java-j2ee-training-course **
This Edureka PPT on Abstract Classes in Java will provide you with detailed knowledge about Abstract Classes in Java and along with it, This PPT will also cover some examples of Abstract Classes in Java, in order to provide you with a deep understanding about their functionality. This PPT will cover the following topics:
What are Abstract Classes in Java?
Why do we need an Abstract Classes in Java?
Rules for using Abstract Classes in Java
Ways to achieve Abstraction in Java
The Syntax for Abstract Classes
Practical Examples of Abstract Classes
Difference between Interface and Abstract Class
Complete Java Playlist: http://bit.ly/2XcYNH5
Complete Blog Series: http://bit.ly/2YoabkT
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
An abstract class is a class that is declared abstract —it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class.
Interface in java By Dheeraj Kumar Singhdheeraj_cse
In Java,
An interface is a way through which unrelated objects use to interact with one another.
Using interface, you can specify what a class must do, but not how it does it.
It is not a class but a set of requirements for classes that implement the interface.
An interface is a reference type in Java. It is similar to the class. It is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface. Along with abstract methods, an interface may also contain constants, default methods, static methods, and nested types.
Interface in java ,multiple inheritance in java, interface implementationHoneyChintal
multiple inheritance in java, interface implementation, abstraction,
multiple inheritance in java using interface, how to use interface,
how to use java, how to execute a java code
An abstract class is a class that is declared abstract —it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class.
Interface in java By Dheeraj Kumar Singhdheeraj_cse
In Java,
An interface is a way through which unrelated objects use to interact with one another.
Using interface, you can specify what a class must do, but not how it does it.
It is not a class but a set of requirements for classes that implement the interface.
An interface is a reference type in Java. It is similar to the class. It is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface. Along with abstract methods, an interface may also contain constants, default methods, static methods, and nested types.
Interface in java ,multiple inheritance in java, interface implementationHoneyChintal
multiple inheritance in java, interface implementation, abstraction,
multiple inheritance in java using interface, how to use interface,
how to use java, how to execute a java code
Abstraction in Java: Abstract class and InterfacesJamsher bhanbhro
In my presentation titled "Abstraction in Java," I have discussed the fundamental concept of abstraction in Java programming. The presentation delves into how abstraction is a key principle in object-oriented programming, explaining its role in hiding the complexity of code while exposing only the necessary details. It includes examples and explanations on implementing abstraction in Java, offering a clear understanding for both beginners and intermediate learners. This presentation serves as an educational guide for those interested in enhancing their Java programming skills and understanding the practical applications of abstraction in software development.
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...Simplilearn
Abstraction is one of the keys to achieving the Object-Oriented Programming approach to design, develop, and deploy software. This technique is really important and many developed intend to have a strong grip on it. This video will give you an idea about the best practices and suggestions that could help you to use abstract classes in Java.
About Simplilearn Java certification training course:
If you’re looking to master web application development for virtually any computing platform, this Java Certification Training course is for you. This all-in-one Java training will give you a firm foundation in Java, the most commonly used programming language in software development.
This advanced Java Certification Training course is designed to guide you through the concepts of Java from introductory techniques to advanced programming skills. The course will provide you with the knowledge of Core Java 8, operators, arrays, loops, methods, and constructors while giving you hands-on experience in JDBC and JUnit framework.
Java Certification Course Key Features:
1. 70 hours of blended training
2. Hands-on coding and implementation of two web-based projects
3. Includes Hibernate and Spring frameworks
4. 35 coding-related exercises on Core Java 8
5. Lifetime access to self-paced learning
6. Flexibility to choose classes
Eligibility:
Simplilearn’s Java Certification Training course is ideal for software developers, web designers, programming enthusiasts, engineering graduates, and students or professionals who wish to become Java developers.
Pre-requisites:
Prior knowledge of Core Java is a prerequisite to taking this advanced Java Certification training course. Our Core Java online self-paced course is available for free to become familiar with the basics of Java programming.
Learn more at: https://bit.ly/3b6SCvp
1.2 Develop code that declares an interface. Develop code
that implements or extends one or more interfaces. Develop
code that extends an abstract class.
1.4 Develop code that declares both static and non-static
methods, and - if appropriate - use method names that
adhere to the JavaBeans naming standards. Also develop
code that declares and uses a variable-length argument list.
5.3 Explain the effect of modifiers on inheritance with
respect to constructors, instance or static variables, and
instance or static methods.
7.1 Given a code example and a scenario, write code
that uses the appropriate access modifiers, package
declarations, and import statements to interact with
(through access or inheritance) the code in the example.
3. From concrete classes
To abstract classes
To interface
Examples:
BJ_1_initial_SalCal
BJ_2_class_SalCal
BJ_3_abstract_SalCal
BJ_4_abstract_method_SalCal
BJ_5_interface_SalCal
4. abstract and final Methods
An abstract method in a superclass has
no implementation, and it is to be
overridden by a method in its subclass.
A final method in a superclass cannot be
overridden at its subclass.
Why do I need to bother with abstract
methods and final methods? Can I live
happily in Java without them?
03/25/13 Abstract classes & Interface 4
5. Abstract Class
A class that cannot instantiate objects.
Message
Text Voice Fax
Message Message Message
Public abstract class Message {
}
Do I and should I use non-abstract methods
in abstract classes?
03/25/13 Abstract classes & Interface 5
6. Abstract or not-abstract
Contains Contains non-
abstract abstract
methods methods
Class abstract May contain OK
abstract methods. E.g. class
abstract methods BJ_abstract_Figure
must be in abstract
classes
GeometricObject in
BJ_GeomObj.
Situation 3
Class non- Not allowed Fine. You are
abstract
03/25/13 Abstract classes & Interface familiar with this
6
7. Example BJ_abstract_Figure
Problems of Bj_FindArea
BJ_abstract_Figure
An abstract class used as supertype
An object cannot be created from an abstract
class
An abstract class can be extended by a
subclass
03/25/13 Abstract classes & Interface 7
8. Example BJ_abstract_Figure2
An abstract class used as supertype
An object cannot be created from an
abstract class
An array of the abstract type is used to
contain objects of the concrete subclasses
03/25/13 Abstract classes & Interface 8
9. Example BJ_GeomObj_Circle9
Circle9 extends an abstract class
GeometricObject
Note the 4 situations in the project:
Circle class has concrete method getArea()
No abstract method getArea(); concrete
getArea() in Circle
abstract method getArea(); concrete
getArea() in Circle
Instantiate object of abstract class
03/25/13 Abstract classes & Interface 9
10. Empty vs abstract methods
Method with empty body
protected abstract double getArea();
Abstract method
protected abstract double getArea();
03/25/13 Abstract classes & Interface 10
12. What is Interface
An interface is a named collection of method
definitions and constants ONLY.
An interface defines a protocol of behavior that
can be implemented by any class anywhere in
the class hierarchy.
An interface defines a set of methods but does
not implement them.
A class that implements the interface agrees to
implement all the methods defined in the
interface, thereby agreeing to certain behaviors.
03/25/13 Abstract classes & Interface 12
13. Interface and Abstract Classes
An interface cannot implement any
methods, whereas an abstract class can.
A class can implement many interfaces
but can have only one superclass.
An interface is not part of the class
hierarchy. Unrelated classes can
implement the same interface.
03/25/13 Abstract classes & Interface 13
14. Multiple Inheritance
Class A Class B Class C
Class ABC
Class ABC inherits all variables and methods from
Class A, Class B, and Class C.
Java does NOT support multiple inheritances.
However, you can use interface to implement the
functionality of multiple inheritance.
03/25/13 Abstract classes & Interface 14
16. Interface Declaration
public interface StockWatcher{ }
public interface Sortable{ }
03/25/13 Abstract classes & Interface 16
17. Interface Body
The interface body contains method
declarations for ALL the methods included
in the interface.
A method declaration within an interface is
followed by a semicolon (;) because an
interface does not provide
implementations for the methods declared
within it.
All methods declared in an interface are
implicitly public and abstract.
03/25/13 Abstract classes & Interface 17
18. Implement an Interface
An interface defines a protocol of
behavior.
A class that implements an interface
adheres to the protocol defined by that
interface.
To declare a class that implements an
interface, include an implements clause in
the class declaration.
03/25/13 Abstract classes & Interface 18
19. Implement Interface (Example)
public class StockApplet extends Applet implements StockWatcher {
...
public void valueChanged(String tickerSymbol, double newValue) {
if (tickerSymbol.equals(sunTicker)) {
// record newValue for sunTicker...
} else if (tickerSymbol.equals(oracleTicker)) {
// record newValue for oracleTicker
} else if (tickerSymbol.equals(ciscoTicker)) {
// record newValue for ciscoTicker
}
}
}
03/25/13 Abstract classes & Interface 19
20. Code Review
BJ_Interface
Objects inheriting properties of superclass
and implementing properties of interface
A class may have only one superclass but
may implement multiple interfaces
Using an array of supertype
polymorphism
03/25/13 Abstract classes & Interface 20
21. Sorting
It is easy to write a sorting method for numbers
of a specific type.
bubblesort, shellsort, quicksort, heapsort.
It is not easy to write a method to sort numbers
of any primitive type: short, int, long, float, and
double.
See Example 9.2 GenericSort.java
It is a challenge to write a method to sort
objects
How do you do the above in C?
03/25/13 Abstract classes & Interface 21
22. Example: Comparable interface
Java.lang.Comparable
See BJ_Max
See BJ_GenericSort
Still relying on Java 1.5 unboxing feature of
wrapper objects
23. Source Code Review and Demo
Exercise 1: Download, run, and study
BJ_Sort/SortTest.java
Each class needs to implement the Sortable
interface with a compare() method
Exercise 2: Add other sorting methods
Bubble, Insertion, Selection
Exercise 3: C:ProgramFilesJava
jdk1.5.0_12demoappletsSortDemo
To compare speed
24. Application Programming
Interface (API)
How do I learn to use the packages in the
Java platform?
Answer: API
http://java.sun.com/j2se/1.5.0/docs/api/
03/25/13 Abstract classes & Interface 24
25. API Study
example: StringTokenizer
1. Location of the API( package)
2. Class definition
3. Constructor(s) – usually more than one
4. Methods (you can see public only)
5. Variables (any public ones)
6. Interfaces – supply your own methods
7. Exceptions
8. Examples
03/25/13 Abstract classes & Interface 25
26. Clone()
newObject = someObject;
Only assigns the reference of someObject to
newObject. No copy is made
newObject = someObject.clone();
Copies someObject to a new memory location
See BJ_House
27. hashCode()
hashCode() returns the object’s hash code
Hash code is an integer to store the object
in a hash set.
If you override the equal() method, you
should also override the hashCode
See BJ_House