0% found this document useful (0 votes)
44 views4 pages

Assignment #2 PDF

Wrapper classes allow primitive data types like int and float to be used as objects by providing equivalent wrapper classes like Integer and Float. An example shows int, float, and char primitive types converted to their wrapper classes and used as objects. Abstract classes cannot be instantiated and are meant to serve as a base for subclasses. They can contain abstract and non-abstract methods as well as constructors and static methods. An example demonstrates an abstract Animal class with a voice method, extended by a Cat class providing an implementation of voice.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views4 pages

Assignment #2 PDF

Wrapper classes allow primitive data types like int and float to be used as objects by providing equivalent wrapper classes like Integer and Float. An example shows int, float, and char primitive types converted to their wrapper classes and used as objects. Abstract classes cannot be instantiated and are meant to serve as a base for subclasses. They can contain abstract and non-abstract methods as well as constructors and static methods. An example demonstrates an abstract Animal class with a voice method, extended by a Cat class providing an implementation of voice.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

ASSIGNMENT “Advanced

Computer Programming” #2

Submitted by: Abdul Daim Rizwan


Section: BSCS F-18 “B”
Wrapper Classes:-
Wrapper classes are classes that are used to use primitive data
types as objects. Primitive data types include int, float,
char…etc. Their equivalent wrapper classes would be Integer,
Float and Character…etc respectively. More wrapper class
equivalent of primitive data types are as follows

Primitive Data Type Wrapper Class

byte Byte

short Short

int Integer

long Long

float Float

double Double

boolean Boolean

char Character
Code Example:
Public class Main ,
public static void main(String*+ args) ,
Integer myInt = 4002;
Double myFloat = 20.99;
Character myChar = 'D';
System.out.println(myInt);
System.out.println(myFloat);
System.out.println(myChar);
-
-

In this example the primitive data types “Int, Float, Char”


are converted to Wrapper class “Integer, Float,
Character” and can be used as objects.
Abstract Classes:-
Abstract class is a class from which we cannot create new
instances. It is declared by adding the abstract keyword to the
class declaration. It can have abstract and non-abstract
methods. It can also have constructors and static methods .The
purpose of an abstract class is to function as a base for
subclasses.

Code Examples:-
abstract class Animal{
public abstract void voice();
}
public class Cat extends Animal{
public void voice(){
System.out.println("Meow");
}
public static void main(String args[]){
Animal obj = new Cat();
obj.voice();
}
}

You might also like