A Critique of the Proposed National Education Policy Reform
Java
1. Ahmed - 1 . Inheritance
Polash - 2 . Polymorphism
Aman - 3 . Overloading
- 4 . Overriding
Mustafiz - 5 . Construction
- 6 . Encapsulation
Galib - 7 . Diff between method n construction
- 8 . Abstract
Welcome to our presentation
2. INTRODUCTION TO INHERITANCE
• Java classes are used in several ways.This is basically
by creating new classes,resuing the properties
existing one.
• The deriving the new class from an old one is called
inheritance .
• The old class is known as base class or super class.
• The class who inherit the properties of the base class
is called derived class or sub class.
3. TYPES OF INHERITANCE
• Single inheritance(one super class)
• Multiple inheritance
• Multilevel inheritance
• Hierarchical inheritance
4. DEFINE SUBCLASS
• Class sub-classname extends super-classname
• {
• variable declaration ;// sub class variables
• method declaration ;// sub class method
• }
• The keyword extends signifies that the properties of
the super class are extended to the sub class.
5. EXAMPLE OF SINGLE INHERITANCE
• Class sum //Super class
• {
• int a=10;
• int b=20;
• void show()
• {
• System.out.println(“value of a :-” +a);
• System.out.println(“value of a :-” +b);
• }
• }
• Class sum2 extends sum //base class
• {
• public static void main(String args[])
• {
• Sum2 obj =new sum2();
• Obj.show1();
}
}
6. 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. Any Java object that can
pass more than one IS-A test is considered
to be polymorphic. Any Java object that can
pass more than one IS-A test is considered
to be polymorphic. In Java, all Java objects
are polymorphic since any object will pass
the IS-A test for their own type and for the
class Object.
Polymorphism
7. Public class Dog extends Animal {
Public void make sound () {
System.out.println(“Woof !”);
}
Public void make sound (Boolean
injured) {
If (injured){
System.out.println(“Whimper”);
}
}
Polymorphism sample code
8. Definition: Overloading occurs when two or more
methods in one class have the same
method name but different parameters.
Overloading
9.
10.
11. Definition:
Overriding means having two methods with the same
method name and parameters. One of the methods is in
the parent class and the other is in the child class.
Overriding allows a child class to provide a specific
implementation of a method that is already provided its
parent class.
12.
13.
14. In the example above, the dog variable is declared
to be a Dog. During compile time, the compiler
checks if the Dog class has the bark() method. As
long as the Dog class has the bark() method, the
code compilers. At run-time, a Hound is created
and assigned to dog. The JVM knows that dog is
referring to the object of Hound, so it calls
the bark() method of Hound. This is called
Dynamic Polymorphism
15. Constructor
A constructor in Java is a block of code similar to a method
that’s called when an instance of an object is created .
Constructor are 2 type
1 . Default constructor (no-arg
constructor)
2 . Parameterized constructor
Default Parameterized
Student obj = new Student ( ) Student obj = new Student ( name )
Difference between default and parameterized constructor
16. Public class StudentResult {
private string Full_Name ;
private string Exam_Name ;
private string Exam_Grade ;
StudentResult( String name , String grade ) {
Full_Name = name ;
Exam_Grade = grade ;
}
Constructor Sample Code
17. Encapsulation is one of the four fundamental OOP
concepts. The other three are inheritance,
polymorphism, and abstraction. Encapsulation in Java is
a mechanism of wrapping the data (variables) and code
acting on the data (methods) together as a single unit. ...
Declare the variables of a class as private.
To achieve encapsulation in Java −
1 . Declare the variables of a class as private.
2 . Provide public setter and getter methods
to modify and view the variables values.
Encapsulation
18. public class EncapTest {
private String name;
private String idNum;
public String getName() {
return name;
}
public String getIdNum() {
return idNum;
}
public void setName(String newName) {
name = newName;
}
public void setIdNum( String newId) {
idNum = newId;
}
}
Encapsulation Sample code
19. Method Constructor
1. Method expose the object
behavior.
1. Constructor initialize the state of
an object.
2. Method name may or may not be
same as the class name.
2. Constructor name must be same
as the class name.
3. . Method must have return
type ..
3. Constructor must not have return
type.
4. Method is invoked explicity . 4. Constructor is invoked implicity .
5. Compiler don’t provide method
any case.
5. Compiler provides a default
constructor if there's no constructor .
Difference Between Method and Constructor
20. Student
- Id : String
- name : String
- mark : String
+ student()
+ student(string:id)
Student
- Id : String
- name : String
- mark : String
+ student() : void
UML Diagram between Constructor and Method
21. Abstract
Abstract : when we don’t create an object
then it is called abstract .
1 . We use it before the concrete class .
2 . It has its own method .
3 . Abstract doesn’t have any body .
4 . Abstract classes cannot be instantiated, but
they can be subclassed.
5 . When an abstract class is subclassed, the
subclass usually provides implementations for all
of the abstract methods in its parent class.
22. Abstract class HelloAbstractWorld { }
Class AbstractDemo {
Public static void main (String ar [ ]) {
System.out.println(“Hello World”);
//HelloAbstractWorld obj = new HelloAbstractWorld
}
} /* HelloAbstractWorld is Abstract and cannot be
intantiated */
Simple Abstract Code