Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: Object Oriented Concept in JAVA
Description: In this Note, we will learn about basics of OOPs. Object Oriented Programming is a paradigm that provides many concepts such as inheritance, data binding, polymorphism etc.

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


OBJECT ORIENTED
PROGRAMMING USING JAVA
Object & Classes

2

Points Covered
 Class
 Object

 Object reference
Static Keyword
Constructor
 Constructor Overloading
 Method Overloading
Recursion
 Passing object form Method
By : Jigar M Pandya

3

Keyword this
 Can be used only inside method
 When to use it?
 method parameter or local variable in a method has the same name as
one of the fields of the class

Used in the return statement when want to return
the reference to the current object
...
w = w; //same name!
}
}

When a method parameter or local variable in a method has
the same name as one of the fields of the class, you must use
this to refer to the field
...
out
...

this
...
name = name;
}
void display(){System
...
println(id+" "+name);}

}

public static void main(String args[]){
Student e1 = new Student(111,"karan");
Student e2 = new Student(222,"Aryan");
e1
...
display();
}

By : Jigar M Pandya

6

Output
default constructor is invoked
default constructor is invoked

111 Karan
222 Aryan

By : Jigar M Pandya

7

Finalization – opposite of initialization
 Garbage collection can ONLY free the memory resources
 Need finalize() to free other resources, for example,
network connection, DB connection, file handler, etc
...
out
...
salary);
System
...
println("Bonus of Programmer is:"+p
...
o
...
o
...
o
...
set_a(10);
o_B
...
show_a();
o_B
...
out
...
display();
}

}
By : Jigar M Pandya

Output
100

Solution by super keyword
15

class Vehicle{
int speed=50;
}
class Bike4 extends Vehicle{
int speed=100;
void display(){
System
...
println(super
...
display();

Output
50

}

By : Jigar M Pandya

}

super can be used to invoke parent class method
16

class Person
{
void message()
{
System
...
println("welcome");
}
}
class Student16 extends Person
{
void message()
{
System
...
println("welcome to java");
}

}

void display()
{
message();
super
...
display();
By : Jigar M Pandya
}

Output
welcome to java
welcome

super is used to invoke parent class constructor
17

class Vehicle
{
Vehicle()
{
System
...
println("Vehicle is created");
}
}

class Bike5 extends Vehicle
{
Bike5()
{
super();//will invoke parent class constructor
System
...
println("Bike is created");
}
public static void main(String args[])
{
Output
Bike5 b=new Bike5();
}

By : Jigar M Pandya

}

Vehicle Is Created
Bike Is Created

18

Types of inheritance in java

Note: Multiple inheritance is not supported in java through class
...
out
...
out
...
msg();
}
}y : Jigar M Pandya
B

21

Abstraction
 Abstraction is a process of hiding the implementation
details and showing only functionality to the user
Ways to achieve Abstraction
 There are two ways to achieve abstraction in java
1
...
Interface

By : Jigar M Pandya

22

Abstract class in Java
 A class that is declared as abstract is known as abstract class
...

 We can not Create object of Abstract class
...
out
...
");
}
public static void main(String args[])
{
Bike obj = new Honda4();
obj
...


Example 2
24

abstract class Shape
{
abstract void draw();
}
class Rectangle extends Shape
{
void draw() {
System
...
println("drawing rectangle");
}

}

class Circle1 extends Shape
{
void draw() {
System
...
println("drawing circle");
}

}

class TestAbstraction1
{
public static void main(String args[])
{
Shape s=new Circle1();
s
...
draw();

Output

drawing circle

By : Jigar M Pandya

drawing rectangle

25

Abstract class having constructor, data
member, methods etc
abstract class Bike
{
Bike(){System
...
println("bike is created");}
abstract void run();
void changeGear(){System
...
println("gear changed");}
}
class Honda extends Bike
{
void run(){System
...
println("running safely
...
run();
obj
...

}
By : Jigar M Pandya

gear changed

26

Interface in Java
 An interface in java is a blueprint of a class
...

 The interface in java is a mechanism to achieve fully
abstraction
...

 It is used to achieve fully abstraction and multiple
inheritance in Java
...


By : Jigar M Pandya

28

relationship between classes and interfaces

By : Jigar M Pandya

29

Simple example of Java interface
interface printable
{
void print();
}
class A6 implements printable
{
public void print(){System
...
println("Hello");}
public static void main(String args[])
{

A6 obj = new A6();
obj
...
out
...
out
...
print();
obj
...
out
...
print();
}
} : Jigar M Pandya
By

Interface inheritance
33

interface Printable
{
void print();
}
interface Showable extends Printable
{
void show();
}
class Testinterface2 implements Showable
{
public void print(){System
...
println("Hello");}
public void show(){System
...
println("Welcome");}

}

public static void main(String args[])
{
Testinterface2 obj = new Testinterface2();
obj
...
show();
}

By : Jigar M Pandya

Difference between abstract class and interface
34

Abstract class

Interface

1) Abstract class can have abstract and nonabstract methods
...


2) Abstract class doesn't support multiple
inheritance
...


3) Abstract class can have final, non-final,
static and non-static variables
...


4) Abstract class can have static methods,
main method and constructor
...


5) Abstract class can provide the
implementation of interface
...


6) The abstract keyword is used to declare
abstract class
...


7) Example:
public abstract class Shape{
public abstract void draw();
}
By : Jigar M Pandya

Example:
public interface Drawable{
void draw();
}


Title: Object Oriented Concept in JAVA
Description: In this Note, we will learn about basics of OOPs. Object Oriented Programming is a paradigm that provides many concepts such as inheritance, data binding, polymorphism etc.