SlideShare a Scribd company logo
Packages
Access Specifiers
Interfaces
Multiple Inheritance
Extending Interface
Interface vs Abstract
Practice Questions
Packages
• Packages in Java is a mechanism to encapsulate a group of classes,
interfaces and sub packages.
• Many implementations of Java use a hierarchical file system to manage
source and class files.
• example: java.lang
Syntax
Package <package name>
This statement should be used in the beginning of the program
/*defining a package*/
package Demo_Package;
public class Demo_Pack
{ public void demo_142()
{ System.out.println("hello world"); }
}
/*importing a package*/
import Demo_Package.*;
public class Demo_1
{
public static void main(String[] y)
{
Demo_Pack p=new Demo_Pack();
p.demo_142();
}
}
Access Specifiers
• private: accessible only in the class
• no modifier: so-called “package” access — accessible only in the same
package
• protected: accessible (inherited) by subclasses, and accessible by code in
same package
• public: accessible anywhere the class is accessible, and inherited by
subclasses
Interface
• Interface is a pure abstract class
• syntactically similar to classes, but you cannot create instance of an
Interface
• Their methods are declared without any body.
• When you create an interface it defines what a class can do without saying
anything about how the class will do it
Syntax for declaring interface
• Interface <interface_name>
• {…}
• Syntax for Declaring interface
Interface <interface_name>
{…}
• Syntax for implementing interface
Classname implements <interface_name>
{…}
interface Demo_ //interface declaration
{ int int_variable=10;
void demo(); // no method body
}
//implementing interface
public class Demo_interface implements Demo_
{ public void demo() //interface body implemented
{ System.out.println("hellow interface"); }
public static void main(String[] args)
{ Demo_interface d=new Demo_interface();
d.demo();
}
}
Multiple inheritance in java
interface Demo_Interface
{ void Demo_Interface(); }
class Demo
{ void Demo_Print_method()
{ System.out.println("the class Demo method called"); }
}
public class Multiple_Inheritance extends Demo implements Demo_Interface
{ public void Demo_Interface()
{ System.out.println("hello Demo_INterface method called"); }
public static void main(String[] args)
{ Multiple_Inheritance MI=new Multiple_Inheritance();
MI.Demo_Print_method(); //class method called
MI.Demo_Interface(); //interface method called
}
}
Extending interface
interface News_Paper_Color
{ void News_Paper_Color(); }
interface Magazine_Paper_Color extends News_Paper_Color
{ void Magazine_Paper_Color(); }
public class Multiple_Inheritance implements Magazine_Paper_Color
{ public void News_Paper_Color()
{ System.out.println("the New Papaer Color red"); }
public void Magazine_Paper_Color()
{ System.out.println("the magazinge paper color yellow"); }
public static void main(String[] args)
{
/*
* we can not create objects for interface class
*/
//News_Paper_Color n=new News_Paper_Color();
Multiple_Inheritance Mi=new Multiple_Inheritance();
Mi.News_Paper_Color();
Mi.Magazine_Paper_Color();
}
}
Abstract Class Interface
Abstract class is a class which contain one
or more abstract methods, which has to
be implemented by its sub classes.
Interface is a Java Object containing
method declaration but no
implementation. The classes which
implement the Interfaces must provide
the method definition for all the
methods.
Abstract class is a Class prefix with an
abstract keyword followed by Class
definition.
Interface is a pure abstract class which
starts with interface keyword.
Abstract class can also contain concrete
methods.
Whereas, Interface contains all abstract
methods and final variable declarations.
Abstract classes are useful in a situation
that Some general methods should be
implemented and specialization behavior
should be implemented by child classes.
Interfaces are useful in a situation that all
properties should be implemented.

More Related Content

PPTX
Z blue interfaces and packages (37129912)
Narayana Swamy
 
PPTX
java interface and packages
VINOTH R
 
PPT
packages and interfaces
madhavi patil
 
PPT
Packages,interfaces and exceptions
Mavoori Soshmitha
 
PPTX
Java interface
BHUVIJAYAVELU
 
PPTX
Interface in java
PhD Research Scholar
 
PPTX
Interfaces in java
Abishek Purushothaman
 
DOCX
Class notes(week 7) on packages
Kuntal Bhowmick
 
Z blue interfaces and packages (37129912)
Narayana Swamy
 
java interface and packages
VINOTH R
 
packages and interfaces
madhavi patil
 
Packages,interfaces and exceptions
Mavoori Soshmitha
 
Java interface
BHUVIJAYAVELU
 
Interface in java
PhD Research Scholar
 
Interfaces in java
Abishek Purushothaman
 
Class notes(week 7) on packages
Kuntal Bhowmick
 

What's hot (20)

PPT
Java interfaces
Raja Sekhar
 
PPT
Interfaces In Java
parag
 
PPTX
Interface &amp;packages
Shah Ishtiyaq Mehfooze
 
PPTX
Java interface
Md. Tanvir Hossain
 
PDF
Java packages
Jeffrey Quevedo
 
PPTX
Lecture 19
talha ijaz
 
PPT
Java access modifiers
Srinivas Reddy
 
PPTX
Simple java program
shalinikarunakaran1
 
PPTX
Java access modifiers
Khaled Adnan
 
PPT
Java interface
Arati Gadgil
 
PDF
JAVA PROGRAMMING – Packages - Stream based I/O
Jyothishmathi Institute of Technology and Science Karimnagar
 
PPTX
Multiple inheritance possible in Java
Kurapati Vishwak
 
PPTX
Packages and interfaces
bhuvaneshwariA5
 
PDF
java-06inheritance
Arjun Shanka
 
PPT
L7 inheritance
teach4uin
 
PPTX
Java interfaces
Elizabeth alexander
 
PPS
Interface
kamal kotecha
 
PPTX
Access modifiers in java
Madishetty Prathibha
 
PPTX
Polymorphism presentation in java
Ahsan Raja
 
PPTX
Interface in java ,multiple inheritance in java, interface implementation
HoneyChintal
 
Java interfaces
Raja Sekhar
 
Interfaces In Java
parag
 
Interface &amp;packages
Shah Ishtiyaq Mehfooze
 
Java interface
Md. Tanvir Hossain
 
Java packages
Jeffrey Quevedo
 
Lecture 19
talha ijaz
 
Java access modifiers
Srinivas Reddy
 
Simple java program
shalinikarunakaran1
 
Java access modifiers
Khaled Adnan
 
Java interface
Arati Gadgil
 
JAVA PROGRAMMING – Packages - Stream based I/O
Jyothishmathi Institute of Technology and Science Karimnagar
 
Multiple inheritance possible in Java
Kurapati Vishwak
 
Packages and interfaces
bhuvaneshwariA5
 
java-06inheritance
Arjun Shanka
 
L7 inheritance
teach4uin
 
Java interfaces
Elizabeth alexander
 
Interface
kamal kotecha
 
Access modifiers in java
Madishetty Prathibha
 
Polymorphism presentation in java
Ahsan Raja
 
Interface in java ,multiple inheritance in java, interface implementation
HoneyChintal
 
Ad

Viewers also liked (20)

PDF
Java OO Revisited
Jussi Pohjolainen
 
PPT
Applying OO Concepts
Mohammed Irfan Shaikh
 
PPTX
Design Pattern lecture 1
Julie Iskander
 
PPT
JavaYDL15
Terry Yoast
 
ODP
Itt1 sd uml and oo
Morten Nielsen
 
PDF
Object oriented fundamentals_in_java
Self
 
PDF
OO & UML
Bin Chen
 
PPTX
Introduction to OO, Java and Eclipse/WebSphere
eLink Business Innovations
 
PPTX
Unified modelling language (UML)
Hirra Sultan
 
PPT
OOP programming
anhdbh
 
PPT
OO Development 3 - Models And UML
Randy Connolly
 
PPT
Module 3 Object Oriented Data Models Object Oriented notations
Taher Barodawala
 
PDF
Yaazli International Spring Training
Arjun Sridhar U R
 
PDF
Java quick reference v2
Christopher Akinlade
 
PPTX
Core java online training
Glory IT Technologies Pvt. Ltd.
 
PPT
02basics
Waheed Warraich
 
DOC
Non ieee dot net projects list
Mumbai Academisc
 
PDF
Yaazli International Web Project Workshop
Arjun Sridhar U R
 
DOCX
Java Exception handling
Garuda Trainings
 
Java OO Revisited
Jussi Pohjolainen
 
Applying OO Concepts
Mohammed Irfan Shaikh
 
Design Pattern lecture 1
Julie Iskander
 
JavaYDL15
Terry Yoast
 
Itt1 sd uml and oo
Morten Nielsen
 
Object oriented fundamentals_in_java
Self
 
OO & UML
Bin Chen
 
Introduction to OO, Java and Eclipse/WebSphere
eLink Business Innovations
 
Unified modelling language (UML)
Hirra Sultan
 
OOP programming
anhdbh
 
OO Development 3 - Models And UML
Randy Connolly
 
Module 3 Object Oriented Data Models Object Oriented notations
Taher Barodawala
 
Yaazli International Spring Training
Arjun Sridhar U R
 
Java quick reference v2
Christopher Akinlade
 
Core java online training
Glory IT Technologies Pvt. Ltd.
 
02basics
Waheed Warraich
 
Non ieee dot net projects list
Mumbai Academisc
 
Yaazli International Web Project Workshop
Arjun Sridhar U R
 
Java Exception handling
Garuda Trainings
 
Ad

Similar to Packaes & interfaces (20)

PPT
Core Java- An advanced review of features
vidyamittal
 
PPT
Java oops PPT
kishu0005
 
PPTX
Interface
Muthiah Abbhirami
 
PPT
02-OOP with Java.ppt
EmanAsem4
 
PPT
025466482929 -OOP with Java Development Kit.ppt
DakshinaPahan
 
PPTX
INTERFACES. with machine learning and data
dineshkesav07
 
PPTX
Unit3 part3-packages and interfaces
DevaKumari Vijay
 
PPTX
Unit3 packages &amp; interfaces
Kalai Selvi
 
PDF
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Alena Holligan
 
PPTX
Structure of java program diff c- cpp and java
Madishetty Prathibha
 
PPTX
it is the quick gest about the interfaces in java
arunkumarg271
 
PPT
Object Oriented Programming with Java
backdoor
 
PDF
Take the Plunge with OOP from #pnwphp
Alena Holligan
 
PDF
Core-java-materiallgfffdfdhgfjfghfchgfhg
komalbhagat8803
 
PDF
OOP in PHP
Alena Holligan
 
PPTX
OOPS_Unit2.inheritance and interface objected oriented programming
ssuserf45a65
 
PPTX
10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx
ssuser7fe189
 
PDF
21UCAC31 Java Programming.pdf(MTNC)(BCA)
ssuser7f90ae
 
PPTX
Lecture 9 access modifiers and packages
manish kumar
 
PDF
Demystifying Object-Oriented Programming - ZendCon 2016
Alena Holligan
 
Core Java- An advanced review of features
vidyamittal
 
Java oops PPT
kishu0005
 
02-OOP with Java.ppt
EmanAsem4
 
025466482929 -OOP with Java Development Kit.ppt
DakshinaPahan
 
INTERFACES. with machine learning and data
dineshkesav07
 
Unit3 part3-packages and interfaces
DevaKumari Vijay
 
Unit3 packages &amp; interfaces
Kalai Selvi
 
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Alena Holligan
 
Structure of java program diff c- cpp and java
Madishetty Prathibha
 
it is the quick gest about the interfaces in java
arunkumarg271
 
Object Oriented Programming with Java
backdoor
 
Take the Plunge with OOP from #pnwphp
Alena Holligan
 
Core-java-materiallgfffdfdhgfjfghfchgfhg
komalbhagat8803
 
OOP in PHP
Alena Holligan
 
OOPS_Unit2.inheritance and interface objected oriented programming
ssuserf45a65
 
10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx
ssuser7fe189
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
ssuser7f90ae
 
Lecture 9 access modifiers and packages
manish kumar
 
Demystifying Object-Oriented Programming - ZendCon 2016
Alena Holligan
 

More from yugandhar vadlamudi (15)

ODP
Toolbarexample
yugandhar vadlamudi
 
ODP
Singleton pattern
yugandhar vadlamudi
 
PPT
Object Relational model for SQLIite in android
yugandhar vadlamudi
 
DOCX
JButton in Java Swing example
yugandhar vadlamudi
 
PPTX
Collections framework in java
yugandhar vadlamudi
 
PPTX
Exception handling in java
yugandhar vadlamudi
 
DOCX
JMenu Creation in Java Swing
yugandhar vadlamudi
 
DOCX
Adding a action listener to button
yugandhar vadlamudi
 
PPTX
Dynamic method dispatch
yugandhar vadlamudi
 
PPTX
Operators in java
yugandhar vadlamudi
 
PPTX
Inheritance
yugandhar vadlamudi
 
PPTX
Control flow statements in java
yugandhar vadlamudi
 
PPTX
Closer look at classes
yugandhar vadlamudi
 
PPTX
java Applet Introduction
yugandhar vadlamudi
 
PPTX
Class introduction in java
yugandhar vadlamudi
 
Toolbarexample
yugandhar vadlamudi
 
Singleton pattern
yugandhar vadlamudi
 
Object Relational model for SQLIite in android
yugandhar vadlamudi
 
JButton in Java Swing example
yugandhar vadlamudi
 
Collections framework in java
yugandhar vadlamudi
 
Exception handling in java
yugandhar vadlamudi
 
JMenu Creation in Java Swing
yugandhar vadlamudi
 
Adding a action listener to button
yugandhar vadlamudi
 
Dynamic method dispatch
yugandhar vadlamudi
 
Operators in java
yugandhar vadlamudi
 
Inheritance
yugandhar vadlamudi
 
Control flow statements in java
yugandhar vadlamudi
 
Closer look at classes
yugandhar vadlamudi
 
java Applet Introduction
yugandhar vadlamudi
 
Class introduction in java
yugandhar vadlamudi
 

Recently uploaded (20)

PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PPTX
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PDF
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PPTX
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Virus sequence retrieval from NCBI database
yamunaK13
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
Basics and rules of probability with real-life uses
ravatkaran694
 

Packaes & interfaces

  • 1. Packages Access Specifiers Interfaces Multiple Inheritance Extending Interface Interface vs Abstract Practice Questions
  • 2. Packages • Packages in Java is a mechanism to encapsulate a group of classes, interfaces and sub packages. • Many implementations of Java use a hierarchical file system to manage source and class files. • example: java.lang Syntax Package <package name> This statement should be used in the beginning of the program
  • 3. /*defining a package*/ package Demo_Package; public class Demo_Pack { public void demo_142() { System.out.println("hello world"); } } /*importing a package*/ import Demo_Package.*; public class Demo_1 { public static void main(String[] y) { Demo_Pack p=new Demo_Pack(); p.demo_142(); } }
  • 4. Access Specifiers • private: accessible only in the class • no modifier: so-called “package” access — accessible only in the same package • protected: accessible (inherited) by subclasses, and accessible by code in same package • public: accessible anywhere the class is accessible, and inherited by subclasses
  • 5. Interface • Interface is a pure abstract class • syntactically similar to classes, but you cannot create instance of an Interface • Their methods are declared without any body. • When you create an interface it defines what a class can do without saying anything about how the class will do it Syntax for declaring interface • Interface <interface_name> • {…}
  • 6. • Syntax for Declaring interface Interface <interface_name> {…} • Syntax for implementing interface Classname implements <interface_name> {…}
  • 7. interface Demo_ //interface declaration { int int_variable=10; void demo(); // no method body } //implementing interface public class Demo_interface implements Demo_ { public void demo() //interface body implemented { System.out.println("hellow interface"); } public static void main(String[] args) { Demo_interface d=new Demo_interface(); d.demo(); } }
  • 8. Multiple inheritance in java interface Demo_Interface { void Demo_Interface(); } class Demo { void Demo_Print_method() { System.out.println("the class Demo method called"); } } public class Multiple_Inheritance extends Demo implements Demo_Interface { public void Demo_Interface() { System.out.println("hello Demo_INterface method called"); } public static void main(String[] args) { Multiple_Inheritance MI=new Multiple_Inheritance(); MI.Demo_Print_method(); //class method called MI.Demo_Interface(); //interface method called } }
  • 9. Extending interface interface News_Paper_Color { void News_Paper_Color(); } interface Magazine_Paper_Color extends News_Paper_Color { void Magazine_Paper_Color(); } public class Multiple_Inheritance implements Magazine_Paper_Color { public void News_Paper_Color() { System.out.println("the New Papaer Color red"); } public void Magazine_Paper_Color() { System.out.println("the magazinge paper color yellow"); } public static void main(String[] args) { /* * we can not create objects for interface class */ //News_Paper_Color n=new News_Paper_Color(); Multiple_Inheritance Mi=new Multiple_Inheritance(); Mi.News_Paper_Color(); Mi.Magazine_Paper_Color(); } }
  • 10. Abstract Class Interface Abstract class is a class which contain one or more abstract methods, which has to be implemented by its sub classes. Interface is a Java Object containing method declaration but no implementation. The classes which implement the Interfaces must provide the method definition for all the methods. Abstract class is a Class prefix with an abstract keyword followed by Class definition. Interface is a pure abstract class which starts with interface keyword. Abstract class can also contain concrete methods. Whereas, Interface contains all abstract methods and final variable declarations. Abstract classes are useful in a situation that Some general methods should be implemented and specialization behavior should be implemented by child classes. Interfaces are useful in a situation that all properties should be implemented.