Sie sind auf Seite 1von 9

Page 1 of 9

Lab Book Of “Object Oriented


Programming”

Submitted By: Kashif


Registration No: (A18BSIT045)

Submitted To: Miss. Sabahat Rija


Page 2 of 9

LAB#01 A18BSIT045

Object:Installation of Java

STEP 1

STEP 2

STEP 3

STEP 4

STEP 5
Page 3 of 9

STEP 6

STEP 7

STEP 8

STEP 9

STEP 10
Page 4 of 9

LAB#02 A18BSIT045

Object: Working with print() Statement

Coding:

class Print{

public static void main(String a[]){

OUTPUT:
Page 5 of 9

LAB#03 A18BSIT045

Object: Working with Scanner Class

Coding:

import java.util.Scanner; float Width=c.nextFloat();

class Area float Area=(Height*Width);

{ float Perimeter=(2*(Height+Width));

public static void main(String a[]) System.out.println(Area);

{ System.out.println(Perimeter);

Scanner c= new Scanner (System.in); System.out.println("KASHIF A18BSIT045


" );
System.out.println("Height");

float Height=c.nextFloat();
}
System.out.println("Width");
}

OUTPUT:
Page 6 of 9

LAB#04 A18BSIT045

Object: Working with Class Members

Coding of Non Static:

class Nonstatic1 Nonstatic1 abc=new


Nonstatic1();
{ System.out.println("The
System.out.println(abc.age=2 exapmle of non static
int age=21; 2); program ");
public static void main(String Nonstatic1 abc2=new }
a[]){ Nonstatic1();
}
System.out.println(" KASHIF System.out.println(abc2.age=
A18BSIT045"); 60);

OUTPUT:

Coding of Static:

class Static System.out.println(" System.out.println(age=35);


KASHIF A18BSIT045");
{
int age=21;
public static void }
main(String a[]) System.out.println(age);
}
{ System.out.println(age=45);

OUTPUT:
Page 7 of 9

LAB#05 A18BSIT045

Object: Working with Data types and type casting

Working with type casting:

There are two types of typecasting:

1) Explicit Typecasting

2) Implicit Typecasting

Coding of Explicit Typecasting:

class Typecasting int c=(int)a; System.out.println("


KASHIF A18BSIT045 ");
{

public static void System.out.println(a);


main(String args[]){ }
System.out.println(b);
double a=142.233473843; }
System.out.println(c);
long b=(long)a;

OUTPUT:

Coding of Implicit Typecasting:

class Typecasting2 float b=a; System.out.println("doubl


e");
{public static void double c=a;
main(String args[]) System.out.println(c);
System.out.println("int");
{ System.out.println(a);Syst System.out.println("
em.out.println("float"); KASHIF A18BSIT045 ");
int a=40;
System.out.println(b); }}

OUTPUT:
Page 8 of 9

LAB#06 A18BSIT045

Object: Working with Conditional Statement:

(1) Working with if else conditional statement


(2) Working with switch conditional statement

Coding of if else conditional statement:

import if(a>=b && a>=c) he greatest number is


java.util.Scanner; " +b);
{
class Number

{ System.out.println("T }
he greatest number is
public static void " +a); else
main (String args[])
{
{
}
Scanner z=new System.out.println("T
Scanner(System.in); he greatest number is:
" +c);
System.out.println("E else if(b>=a &&
nter three numbers"); b>=c)

int a=z.nextInt(); { }

int b=z.nextInt(); }
System.out.println("T
int c=z.nextInt(); }

OUTPUT:
Page 9 of 9

Coding of Switch conditional statement:

import java.util.Scanner; System.out.println(" } break;


its a vowel");
class Switch{ case 'u':{
} break;
public static void System.out.println("
main(String args[]){ case 'e':{ its a vowel");

Scanner c=new System.out.println(" }break;


Scanner(System.in); its a vowel");
default: {
System.out.println("Kashif }break;
A18BSIT045"); System.out.println("
case 'i':{ its a consonant");
System.out.println(" Enter
the character "); System.out.println("
its a vowel"); }
char ch=c.next().charAt(0);
}break;
switch(ch){
case 'o':{ }
case 'a':{
System.out.println(" }
its a vowel");
}

OUTPUT:

Das könnte Ihnen auch gefallen