EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Types of methods:

 

class Methods

{

public void add()//without returntype/without argument

{

int a=123;

int b=10;

System.out.println(“Addition=” +(a+b));

}

}

class Functiondemo

{

public static void main(String args[])

{

Methods o=new Methods();//classname objectname=new classname();

o.add();

}

}

 

import java.util.*;

class Methods

{

public void sub(int x,int y)//without returntype/with /arguments

{

System.out.println(“Subtraction=” +(x-y));

}

}

class Functiondemo

{

public static void main(String args[])

{

Methods o=new Methods();

Scanner s=new Scanner(System.in);

int a=s.nextInt();

int b=s.nextInt();

o.sub(a,b);

}

}

 

class Methods

{

public int mul()//with returntype/without arguments

{

int a=123;

int b=10;

return a*b;

}}

class Functiondemo

{

public static void main(String args[])

{

Methods o=new Methods();

int x=o.mul();

System.out.println(x);

}

}

 

class Methods

{

public float div(int x,int y)//with returntype/with arguments

{

return (x/y);

}

class Functiondemo

{

public static void main(String args[])

{

Methods o=new Methods();

System.out.println(“Division=” +o.div(123,10));

}

}

 

//Invoking the methods:

 

class Box

{

int length;

int breadth;

int height;

 

int volume()

{

return length*breadth*height;

}

}

class Demo

{

public static void main(String args[])

{

Box a=new Box();

a.length=10;

a.breadth=8;

a.height=6;

//a.volume();invoking method

System.out.println(“Volume of SteelBox=” +a.volume());

 

Box b=new Box();

b.length=30;

b.breadth=24;

b.height=25;

//b.volume();invoking method

System.out.println(“Volume of WoodBox=” +b.volume());

}

}

class Demo

{

int length;

int breadth;

int height; //10 //4 //6

static int boxvolume(int length,int breadth,int height)

{

int vol=length*breadth*height;//10*4*6

return vol;

}

}

class MMain

{

public static void main(String[] args)

{

System.out.println(Demo.boxvolume(10,4,6));

}

}

Types of methods in java

Leave a Reply

Your email address will not be published. Required fields are marked *

EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Popular Courses

[Course Image]

Introduction to Programming

Learn the fundamentals of programming with Python in this beginner-friendly course.

12 Hours Beginner
[Course Image]

Data Science Essentials

Master the basics of data analysis, visualization, and machine learning.

20 Hours Intermediate
[Course Image]

Web Development Bootcamp

Build modern websites with HTML, CSS, JavaScript and popular frameworks.

30 Hours Beginner
[Course Image]

Digital Marketing Fundamentals

Learn SEO, social media marketing, email campaigns and analytics.

15 Hours Beginner
Educational Website Footer