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

Practicle No.1 Akshit Sharma 18BCS1682 CSE-7 (A) : Ques1. Write A Program To Create Classes and Use Different

The document contains code snippets that demonstrate different types of methods in Java classes. It includes an example of a class with non-static methods that insert data into an object and display it, and a main method that creates an object and calls these methods. It also shows a class with a static method that performs addition without creating an object, and calls this static method from main.

Uploaded by

Rahul S. Chauhan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Practicle No.1 Akshit Sharma 18BCS1682 CSE-7 (A) : Ques1. Write A Program To Create Classes and Use Different

The document contains code snippets that demonstrate different types of methods in Java classes. It includes an example of a class with non-static methods that insert data into an object and display it, and a main method that creates an object and calls these methods. It also shows a class with a static method that performs addition without creating an object, and calls this static method from main.

Uploaded by

Rahul S. Chauhan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

PRACTICLE NO.

1
AKSHIT SHARMA
18BCS1682
CSE-7(A)
Ques1. Write a program to create classes and use different
types of method.
Code:
class Employee
{

int id;

String name;

int salary;

void insert(int i, String n,int s)

id=i;

name=n;

salary=s;

}
void display()

System.out.println(id);

System.out.println("name");
System.out.println(salary);

class Main

public static void main(String [] args)

Employee e=new Employee();

e.insert(1000,"Riya",10000);

e.display();

}
}
Output:

Ques2. Write a program to create a code with static method.


Code:
class Main

int add(int a,int b)

int sum=a+b;

return sum;

static int add1()


{

return (10+4);

public static void main(String []args)

Main obj=new Main();

int s=obj.add(10,20);

System.out.println(s);

int z=add1();

System.out.println(z);

}
Output:

You might also like