Sampath Kumar S Assistant Professor, SECE

Slides:



Advertisements
Similar presentations
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Advertisements

INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Constructors And Instantiation. Constructor Basics Every class must have a constructor Even abstract classes!! No return types Their names must exactly.
The Java Programming Language  Simple – but abstract  Safe  Platform-independent ("write once, run anywhere")  Has a Rich growing library  Designed.
1 Lecture 06(Abstract Classes)Lecture 9 Abstract Classes Overview  Abstract Classes: A Definition.  Declaring Abstract Classes.  Abstract Methods: A.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Object-oriented analysis (OOA) techniques are used to (1) study existing objects to see if they can be reused or adapted for new uses, and (2) define new.
Programming With Java ICS201 University Of Ha’il1 Chapter 8 Polymorphism and Abstract Classes.
Inheritance. Introduction Inheritance is one of the cornerstones of object-oriented programming because it allows the creation of hierarchical classifications.
1 Classes and Objects in Java Basics of Classes in Java.
1 final (the keyword, not the exam). 2 Motivation Suppose we’ve defined an Employee class, and we don’t want someone to come along and muck it up  E.g.,
1 Interfaces and Abstract Classes Chapter Objectives You will be able to: Write Interface definitions and class definitions that implement them.
1 Abstract Classes and Interfaces. 2 The abstract Modifier  The abstract class –Cannot be instantiated –Should be extended and implemented in subclasses.
MIT AITI 2004 – Lecture 13 Abstract Classes and Interfaces.
Object Oriented Programming with Java 03 - Introduction to Classes and Objects.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Java Programming Final Keyword In Java. final keyword The final keyword in java is used to restrict the user. The final keyword can be used in many context.
Peyman Dodangeh Sharif University of Technology Fall 2014.
1 / 41 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 5 Programming Fundamentals using Java 1.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
OOP Basics Classes & Methods (c) IDMS/SQL News
Interfaces & Abstract Classes (For CS III AP) March 2014.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
CSC 205 Programming II Lecture 4 Abstract Class. The abstract keyword indicate that a class is not instantiable Defining a type which will be specialized.
 The word static is used to declare either a ________ variable or method.  Why do we use statics?  What is Polymorphism? class In general, we use a.
Java Interfaces CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University (see Chapter 9 of.
Modern Programming Tools And Techniques-I
GC211 Data structure Lecture 3 Sara Alhajjam.
Web Design & Development Lecture 9
Inheritance in Java Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object. The idea behind.
Inheritance-Basics.
Final and Abstract Classes
Interface.
INHERITANCE IN JAVA.
Building Java Programs
Programming in Java Text Books :
Class vs Abstract vs Interface
Modern Programming Tools And Techniques-I Inheritance
OOP’S Concepts in C#.Net
Interface.
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Interfaces.
Sampath Kumar S Assistant Professor, SECE
Sampath Kumar S Assistant Professor, SECE
METHOD OVERRIDING in JAVA
S.VIGNESH Assistant Professor/CSE, SECE
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Sampath Kumar.S Assistant Professor/IT, SECE
S.VIGNESH Assistant Professor, SECE
Sampath Kumar S Assistant Professor, SECE/IT
Method Overloading in JAVA
Sampath Kumar S Assistant Professor, SECE
Inheritance Inheritance is a fundamental Object Oriented concept
Method Overriding in Java
Sampath Kumar S Assistant Professor, SECE
Graphics Programming - Frames
Input and Output Stream
Inheritance Cse 3rd year.
Sampath Kumar S Assistant Professor, SECE
class PrintOnetoTen { public static void main(String args[]) {
Constructors, GUI’s(Using Swing) and ActionListner
Chapter 14 Abstract Classes and Interfaces
Inheritance and Polymorphism
Sampath Kumar S Assistant Professor, SECE
Final and Abstract Classes
Sampath Kumar S Assistant Professor, SECE
Chapter 11 Inheritance and Encapsulation and Polymorphism
Interfaces,Packages and Threads
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

Sampath Kumar S Assistant Professor, SECE Abstract class Sampath Kumar S Assistant Professor, SECE

Abstraction 11/29/2018 Abstraction is a process of hiding the implementation details and showing only functionality to the user. Another way, it shows only important things to the user and hides the internal details for example sending SMS, you just type the text and send the message. You don't know the internal processing about the message delivery. Abstraction lets you focus on what the object does instead of how it does it. Sampath Kumar S, AP

Ways to achieve Abstraction 11/29/2018 Ways to achieve Abstraction There are two ways to achieve abstraction in java Abstract class Interface Sampath Kumar S, AP

Abstract class 11/29/2018 A class that is declared as abstract is known as abstract class. It needs to be extended and its method implemented. It cannot be instantiated. Syntax to declare the abstract class abstract class <class_name> { }   Sampath Kumar S, AP

Abstract Method 11/29/2018 A method that is declared as abstract and does not have implementation is known as abstract method. Syntax to declare the abstract method abstract return_type <method_name>(); //no braces{}   Sampath Kumar S, AP

Example: abstract method 11/29/2018 abstract class Bike{ abstract void run(); } class Honda extends Bike{ void run(){ System.out.println("running safely"); public static void main(String args[]){ Bike obj = new Honda(); obj.run(); Output: running safely Sampath Kumar S, AP

11/29/2018 Example: Scenario abstract class Shape{   abstract void draw();   }     class Rectangle extends Shape{   void draw(){ System.out.println("drawing rectangle"); }  }     class Circle extends Shape{   System.out.println("drawing circle"); class Test{   public static void main(String args[]){   Shape s=new Circle();   s.draw();   }  }  Note: Shape is the abstract class, its implementation is provided by the Rectangle and Circle classes. Output: drawing circle Sampath Kumar S, AP

Example: Method Output: This is third IT All Students are good!!! 11/29/2018 Example: Method abstract class finalIt { abstract void student(); void goodStudents(){ System.out.println(“All Students are good!!!"); } } class thirdIt extends finalIT { void student(){ System.out.println(“This is third IT"); } public static void main(String args[]){ finalIt obj = new thirdIt(); obj.student(); obj.goodStudents(); } Output: This is third IT All Students are good!!! Sampath Kumar S, AP

Example: Constructor, field and method 11/29/2018 Example: Constructor, field and method abstract class finalIt { int total=52; finalIt(){ System.out.println("constructor is invoked"); } void getDetails(){ System.out.println(“All Students are good!!!"); } void student(){ } } class thirdIt extends finalIT { void student(){ System.out.println(“This is third IT"); } public static void main(String args[]){ finalIt obj = new thirdIt(); obj.student(); obj. getDetails(); System.out.println(obj.total); } Output: constructor is invoked This is third IT All Students are good!!! 52 Sampath Kumar S, AP

11/29/2018 Some Rules: If there is any abstract method in a class, that class must be abstract. Example class Bike{   abstract void run();   }   While extending any abstract class that have abstract method, provide either the implementation of the method or make the class abstract. Output: compile time error Sampath Kumar S, AP

11/29/2018 Sampath Kumar S, AP

11/29/2018 Thank You  Sampath Kumar S, AP