0% found this document useful (0 votes)
69 views

Bitwise Class Static Overloading

The document contains 5 programming assignments in Java: 1) A program to demonstrate the difference between signed and unsigned right shifts. 2) A BankAccount class with methods to set initial values, deposit amounts, and display account details. 3) A program using static blocks to initialize static variables when the class is loaded. 4) A Product class with static and non-static methods to set product details and count total products. 5) A program demonstrating method overloading with different Display() methods for no arguments, a string argument, and a string and integer argument.

Uploaded by

VAISHALI CHANDEL
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)
69 views

Bitwise Class Static Overloading

The document contains 5 programming assignments in Java: 1) A program to demonstrate the difference between signed and unsigned right shifts. 2) A BankAccount class with methods to set initial values, deposit amounts, and display account details. 3) A program using static blocks to initialize static variables when the class is loaded. 4) A Product class with static and non-static methods to set product details and count total products. 5) A program demonstrating method overloading with different Display() methods for no arguments, a string argument, and a string and integer argument.

Uploaded by

VAISHALI CHANDEL
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/ 6

Subject : Java Programming

Assignment : 8

1.Write a Simple Java Program that demonstrate the difference between signed right
shift (>>) and unsigned right shift(>>>).

import java.util.*;
class shift
{
public static void main(String args[])
{
//Signed Right shift
int a = 4;
System.out.println(a>>2);

int b = -9;
System.out.println(b>>2);

//Unsigned Right shift


int c = 1;
System.out.println(c>>>3);

int d = -6;
System.out.println(d>>>29);
}
}

Output :

2. Design a class to represent bank Account having following


Data Members : Name of Account holder , Account Type , Account Number ,
balance
Member Methods :
To assign initial values: setAccount() method.
To display name ,account no, balance : getAccount()
To deposit amount : deposit() using which amount can be deposited into account

186150316006 Page no : 1
Subject : Java Programming
import java.util.*;
class account
{
String Acc_name;
String Acc_type;
int Acc_number;
int Acc_balance;
int deposit,total;

void setaccount(String n,String t,int no,int b)


{
Acc_name=n;
Acc_type=t;
Acc_number=no;
Acc_balance=b;
}

void deposit (int a)


{
deposit=a;
total=Acc_balance+deposit;
}

void getaccount()
{
System.out.println("Account holder name : "+Acc_name);
System.out.println("Account type : "+Acc_type);
System.out.println("Account number : "+Acc_number);
System.out.println("Account balance : "+Acc_balance);
System.out.println("Deposit amount : "+deposit);
System.out.println("total amount : "+total);
}
}
class Main
{
public static void main(String args[])
{
account a=new account ();
a.setaccount("Vaishali", "Saving account",112233,4100);
a.deposit(3000);
a.getaccount();
}
}

Output :

186150316006 Page no : 2
Subject : Java Programming

3. Write a Simple Java Program to demonstrate the concept of static blocks.

class Test
{
static int i, j;
static
{
i = 10;
System.out.println("static block1 called.. ");
}
static
{
j=20;
System.out.println("static block2 called.. ");
}
}
class Main
{
public static void main(String args[])
{
System.out.println("main method called.."+Test.j);
}
static
{
System.out.println("static block3 called.. "+Test.i);
}
}

Output :

186150316006 Page no : 3
Subject : Java Programming

4.Design a Class to represent a Product having following


Data Members : Product Name , Company Name , price
Member Methods :
To assign initial values : setProduct() Method
To display product information: getProduct() Method.
Create one method to get the updated value of total product created by you using
the concept of static variable and static Method.

import java.util.*;
class product
{
String P_name;
String P_company;
int price;
static int count=0;

void setproduct(String n, String c,int p)


{
P_name=n;
P_company=c;
price=p;
count++;
}

void getproduct ()
{
System.out.println("product name : "+P_name);
System.out.println("Product company : "+P_company);
System.out.println("product price :"+price);
}
}

class P
{
public static void main(String args[])

186150316006 Page no : 4
Subject : Java Programming
{
product p=new product ();
p.setproduct("Hello","abc",300);
p.getproduct();
System.out.println();
product p1=new product ();
p1.setproduct("Hii","xyz",100);
p1.getproduct();
System.out.println();
product p2=new product ();
p2.setproduct("Good","xyz",400);
p2.getproduct();
System.out.println("\nTotal number of products:"+product.count);
}
}

Output :

5. Write a program to demonstrate the use of method overloading with below


example:
Display() : it simply displays “no argument is specified.”
Display(String s): it displays the string specified by String argument.
Display(String s , int n): it displays the displays the string specified by
String arguments n times.

186150316006 Page no : 5
Subject : Java Programming
import java.util.*;
class overloading
{
void display ()
{
System.out.println("no argument in specified..");
}
void display (String s)
{
System.out.println("String specified by string argument..");
System.out.println(" "+s);
}
void display (String s,int n)
{
System.out.println("String specified by string and int argument.. ");
for(int i=0;i<n;i++)
{
System.out.println(" "+s);
}
}
}
class main
{
public static void main(String args[])
{
overloading o = new overloading ();
o.display();
o.display("Hello");
o.display("Hello",6);
}
}
Output :

186150316006 Page no : 6

You might also like