Professional Documents
Culture Documents
What is Abstraction?
• Making things more general, simpler, abstract
behavior(Interface)
and object.
Access Specifiers
•Provide Control access to class members
•Help to implement:
•Encapsulation
•Abstraction
private int x;
private int y;
int a,b;
}
Class Declaration for point-modified
class Point{
private int x;
}
class PointDemo{
int a,b;
p1.setX(22);
p1.setY(44);
Output:
a=p1.getX( );
The Value of a is 22
System.out.println("The Value of a is " + a); The Value of b is 44
b=p1.getY( );
}
Predict the answer
1. Which among the following best defines abstraction?
a)Hiding the implementation
b) Showing the important data
c) Hiding the important data
d) Hiding the implementation and showing only the features
Predict the answer
2. Abstraction gives higher degree of ________
a) Class usage
b) Program complexity
c) Idealized interface
d) Unstable interface
Predict the output
class Test
{ int a; int b;
Test(int a, int b) Output:
{ a = a; b = b; } this.a=a;this.b=b 00
void display()
{ System.out.println("a = " + a + " b = " + b); }
public static void main(String[] args)
{ Test object = new Test(10, 20); object.display(); }
}
Inheritance
IS-A relationship
HAS-A relationship(Aggregation)
extends IS - A
class bike extends Vehicle {
class Vehicle
extends
class RegVechicle
extends
class Bike
extends
class MountainBike
Types- Multilevel
class Vehicle{
int noOfWhe;}
class RegisteredVehicle extendsVehicle{
String regNo;}
class Bike extends RegisteredVehicle {
boolean hasHel;}
class MountainBike extends Bike{
double maxEle;}
Types- Multilevel
class TestVehiclesHierarchy
{ public static void main(String arg[]) {
MountainBike mb = new MountainBike();
mb.noOfWhe = 2;
mb.regNo = "APXX WWW";
mb.hasHel= true;
mb.maxEle= 3000.0;
System.out.print("Mountain Bike with registration Number " + mb.regNo);
System.out.println(" is supported till the elevation of " + mb.maxEle + "
feet.");
}
}
Output:
Mountain Bike with registration Number APXX WWW is
supported till the elevation of 3000.0 feet.
Types - Hierarchical
class Species