Presentation is loading. Please wait.

Presentation is loading. Please wait.

OOP Aga private institute for computer science 5th grade

Similar presentations


Presentation on theme: "OOP Aga private institute for computer science 5th grade"— Presentation transcript:

1 OOP Aga private institute for computer science 5th grade
Lecturer : Srwa Mohammad

2 Abstraction Abstract class: is a class that cant be instantiated because they are incomplete classes, they only used to be super class for concrete subclass We can make a class or method abstract simply by using abstract keyword ex: public abstract void add(); Any class that contain an abstract method must be abstract class even it include (non-abstract) methods too. Note: Constructors and Static methods could never be an abstract.

3 Encapsulation Encapsulation is the bending together of code and data to keep both of them safe from out side interface and misuse For example private data and codes for an object cant be reached by any other parts of program without permission from that object. So we can say this object is encapsulated.

4 Interfaces In java we can only extend one class, but some times we need more than one super class in sub class in this situation we have to use interfaces. Concept of interface: concrete subclass can be inherited from only one class, but it also can use the useful contents from interfaces methods. Interface is like class but it can only contain abstract methods Any class that implements interface must define the interface method or must be an abstract class it self. To use the interface we use (implements) keyword

5 Packages Package: is a collection of related classes and interfaces providing access protection and namespace management Packages are useful for managing the complicity of applications, and to support software reusability. To handle group of related classes we use packages for example: for input data we use (java.util.Scanner) package

6 How to create and use a package?
Package declaration statement should be the first statement in the file which contains the classes or interfaces. To use class of a package, use import statement to import classes of that package to your program. If there is multiple classes in a file, only 1 of them can be public, so only that public class can be accessed outside the package.

7 Package example package MyPack; public class math1 { public static double add(double a, double b) return a+b; } public class math2 public static double sub(double a, double b) return a-b;

8 package MyPack; public class math3 { public static double mult(double a, double b) return a*b; } public class math4 public static double div(double a, double b) return a/b;

9 //sub package imports objects in a package MyPack by a class called oopEx //using * means all classes in this package can be used import MyPack.*; public class oopEx { public static void main(String[]ags) double a=5; double b=10; System.out.println(math1.add(a,b)); System.out.println(math2.sub(a,b)); System.out.println(math3.mult(a,b)); System.out.println(math4.div(a,b)); }


Download ppt "OOP Aga private institute for computer science 5th grade"

Similar presentations


Ads by Google