Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Problem Logic

Practice
Solving Building

Object Oriented Programming


Course Code: CSAO-267, Sem:4
Pre: CSOO-142-Sem:2
By Zohair Ahmed

1 Practice More
By Zohair Ahmed
Wrapper Classes
▸Boxing:It is manual method to convert primitive type data into non-primitive type .
▸int num=7;
▸Integer num1=new Integer(8); //boxing

▸UnBoxing: It is manual method to convert non-primitive data type to primitive type.


▸int num2=num1.intValue(); //unboxing

▸AutoBoxing:It is automatic conversion of primitive type data into non-primitive data type.
▸int num3=5;
▸Integer num4=num3; //autoboxing

▸AutoUnBoxing:It is automatic conversion of non primitive type data into primitive data type.
▸int num5=num4; //autounboxing

By Zohair Ahmed
Abstract Keyword
▸Abstraction is a process of hiding the implementation details and showing only functionality to the
user.
▸Abstract method
▸Instead of defining the method, we can declare the method. - If we put a semicolon at the end of a
method, it means that you only declare the method like: public void drive();
▸ This method does not contain any features and you will not be able to create an object of it. - You
need to add an abstract keyword to only declare a method.
▸Abstract class
▸Abstract methods can only be defined in an abstract class.
▸We need to add an abstract keyword before a class to make it an abstract class.
▸Objects of an abstract class can not be created.
▸If you are extending an abstract class, then it is compulsory to define all abstract methods.
▸It is not necessary that an abstract class should have an abstract method
▸Abstract class can have an abstract or a normal method or both. - An abstract class can have more
than one abstract method.
▸Concrete class: A class other than an abstract class is known as a concrete class. - An object of a
concrete class can be created.
3

By Zohair Ahmed
Abstract Keyword
abstract class car {
abstract void engine();

public void playmusic() {


System.out.println("Music Playing");
}
}

class suzuki extends car {

public void engine() {


System.out.println("Engine");
}
}

public class test {


public static void main(String[] args) {
suzuki obj = new suzuki();
obj.playmusic();
obj.engine();
}
}
//Music Playing
4
//Engine
By Zohair Ahmed
class A {
int age = 35;
Inner Class
public void show() {
We can also create a class inside another System.out.println("In Show A");
class. }
You can call the method of class B by using
class B {
the dot operator in between both classes
public void settings() {
A and B. A.B obj= new B(); System.out.println("the config and settings");
}
}
}

public class test {


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

//Call Inner Class


A.B obj1 = obj.new B();
obj1.settings();
}
}
5

By Zohair Ahmed
Interfaces interface A {
▸If class only abstract methods use an
void show();
void settings();
interface, Interface is not any class. }
▸Every method in an interface is public and class B implements A{
public void show() {
abstract by default. System.out.println("In Show A");
▸We cannot instantiate an interface. - Interface }public void settings() {
System.out.println("the config and settings");
only shows the design and it does not provide }

any implementation. - To provide an }

implementation of methods, you need to public class test {


public static void main(String[] args) {
create a class and instantiate it also. B obj = new B();
obj.show();
▸We can also declare variables in an interface. - obj.settings();
}
All the variables in an interface are final and }
6 static by default.
By Zohair Ahmed
interface A {
Multiple Interfaces void show();
void settings();
▸class - class – extends }
interface X {
▸class - interface – implements
void run();
}
▸interface - interface - extends class B implements A,X{
public void show() {
System.out.println("In Show A");
}
public void settings() {
System.out.println("the config and settings");
}

public void run() {


System.out.println("Running");
}

}
public class test {
public static void main(String[] args) {
B obj = new B();
obj.show();
obj.settings();
obj.run();
}
}
7

By Zohair Ahmed

You might also like