Green University of Bangladesh: Department of Computer Science and Engineering Assignment

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

GREEN UNIVERSITY OF BANGLADESH

Department of Computer Science and Engineering

assignment

Course Title : Object Oriented Programming

Course Code : CSE - 202

Submitted to: Submitted by:


Name : Himel Chandra Das
Name : Dr. Muhammad Aminur Rahaman
ID : 193002140
Designation : Assistant Professor
Section : DA
Department Of CSE
Department Of CSE
Class: A CLASS is a template used to create objects and to define object data types and methods. Class
in Java determines how an object will behave and what the object will contain.

Object: An OBJECT is an instance of a class. Classes are categories, and objects are items within each
category like variables, methods.

Method: A method is a block of code or collection of statements or a set of code grouped together
to perform a certain task or operation. It is used to achieve the reusability of code. We write a
method once and use it many times.

CONSTRUCTOR: CONSTRUCTOR is a special method that is used to initialize a newly created


object
and is called just after the memory is allocated for the object.

Method and Constructor difference: Method is used to expose behavior of an object.


Constructor is used to initialize the state of an object. Method must have return type. Constructor
must have return type. Method name may or may not be same as class name. Constructor name
must be same as the class name.

Method overloading and Constructor overloading difference: If we have to


perform only one operation, having same name of the methods increases the readability of the
program. Constructor overloading in java is a technique of having more than one constructor with
different parameter lists. They are arranged in a way that each constructor performs a different
task.

Program:
public class Main {

public static void main(String[] args) {

Teacher obj1 = new Teacher();

obj1.displayMethod();

Teacher obj2 = new Teacher("Himel",193002140,20000);

obj2.displayMethod();

Teacher obj3 = new Teacher(obj1);

obj3.displayMethod();

}
class Teacher {

private String name;

private int id;

private int salary;

Teacher() {

Teacher(String nam, int i, int s) {

name = n;

id = i;

salary = s;

Teacher(Teacher obj1) {

void displayMethod() {

System.out.print(name+" "+id+" "+salary);

You might also like