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

Lab 1

Uploaded by

Lojain Fallatah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views4 pages

Lab 1

Uploaded by

Lojain Fallatah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Data Structures and Algorithms / CS211 Lab Manu

Date: 08 / 09/2020

Department of Forensic Computing and Cyber Security


College of Computer Science and Information Technology

Lab1: Java P
1. Objectives
In this lab, students review Java language by doing the following tasks:

 Use one/many classes


 Create one or number of objects and know how to interact with objects.
 Create attributes and learn how to access attributes and modify it.
 Know how to use Java methods and call it.
 Create constructor.
 Create Exception
 Create interface and implement
 Create abstract class

Task1 :
1- Create class called LabOne with attribute x=1

2- Create object of the class LabOne called object1 and print the value of attribute x

3- Create another attribute called y=2 and object called object2

4- Print the value of both x and y using this format x= 1 ,y= 2

5- Use object1 to change the value of attribute x x=3. Using setter method.

6- Declare y as constant by using final.


Note that :
In Java, when final keyword is used with a variable of primitive data types
(int, float, .. etc), value of the variable cannot be changed.

7- Create static method called staticMethod, add print statement “Static”.


Call this method from main method.
Note that: A static method can be called directly from the class, without having to create an
instance of the class.
8- Create public method called publicMethod, add print statement “Public”.
Call this method from main method.
Data Structures and Algorithms / CS211 Lab Manu
Date: 08 / 09/2020

9- Create public method called name with String parameter s.


Add print statement inside the method ("My name is "+ s)
Call the method with your name from main method.
Homework:
10- Create constructor of the class LabOne and create new attribute z.
Use constructor to set the value of z z=4.
Print the value of z from the main method.
11- Create static method called number that takes integer parameter x and return value.
Call this method from main method.

12- Create another class in the same file called LabOne2.


Add method called sum that takes two integer and print the sum of it.
Call the method from class LabOne.
Data Structures and Algorithms / CS211 Lab Manu
Date: 08 / 09/2020

Task 2

13- Create an abstract class called Vehicle which attributes V_ID and V_name. The class has method
called getName and another abstract method called getID.

14- Create subclass of the Vehicle called Car with attribute C_Year (i.e. creation year) and give the
get_ID method a body.

15- In the main method Create an object of the Car with a reference of type Vehicle then call
get_name and get_ID.
Data Structures and Algorithms / CS211 Lab Manu
Date: 08 / 09/2020

You might also like