Opening Hours :7AM to 9PM
Binding of attributes and behaviors in a single container .In java language it can be achieved by 'class' keyword.
class:
'class' is container which is collection of variable and methods (or) it is a blueprint of the object.
Syntax:
Variable:
Variable is an identifer whose value can can be changed.
Example:
int x=10;
x=20;
In java language these variable are classified into following types
1.Local variable
2.Global variable
3.Formal variable
4.Block variable
Local variable:
If any variable declare with in method or constructor.
Global variable
If any variable declare with in class or outside of the method or constructor.
Formal variable
If any variable declare with in method signature or constructor signature.
Block variable
If any variable declare with in block(if block ,for block ete..)
class LocalGlobal
{
int x; //Global Varaible
void show()
{
int y=10;//Local Variable
x=100;
System.out.println("x value is "+x);
System.out.println("y value is "+y);
}
void disp()
{
int z=20;//Local Variable
x=200;
System.out.println("x value is "+x);
//System.out.println("y value is "+y);
System.out.println("z value is "+z);
}
}
class Main
{
public static void main(String args[])
{
LocalGlobal d=new LocalGlobal();
d.show();
d.disp();
}
}
Method is a collection of statements used to perform specific operation.
accessmodifiers returntype methodname(list of parameters/no parameters)
{
..
..
..
}
accessmodifiers returntype methodname()
{
..
..
..
}
accessmodifiers returntype methodname(datatype variable1,datatype variable2,....)
{
..
..
..
}
class Maxnum
{
void max()
{
int x=10,y=20;
if(x>y)
{
System.out.println("x is Max");
}
else
{
System.out.println("y is Max");
}
}
}
class Main
{
public static void main(String args[])
{
Maxnum m=new Maxnum();
m.max();
}
}
import java.util.*;
class Maxnum
{
void max()
{
int x,y;
Scanner s=new Scanner(System.in);
System.out.println("Enter x ,y values");
x=s.nextInt();
y=s.nextInt();
if(x>y)
{
System.out.println("x is Max");
}
else
{
System.out.println("y is Max");
}
}
}
class Main
{
public static void main(String args[])
{
Maxnum m=new Maxnum();
m.max();
}
}
class Maxnum
{
void max(int x,int y)
{
if(x>y)
{
System.out.println("x is Max");
}
else
{
System.out.println("y is Max");
}
}
}
class Main
{
public static void main(String args[])
{
Maxnum m=new Maxnum();
m.max(10,20);
}
}
import java.util.*;
class Maxnum
{
void max(int x,int y)
{
if(x>y)
{
System.out.println("x is Max");
}
else
{
System.out.println("y is Max");
}
}
}
class Main
{
public static void main(String args[])
{
Maxnum m=new Maxnum();
int a,b;
Scanner s=new Scanner(System.in);
System.out.println("Enter a ,b values");
a=s.nextInt();
b=s.nextInt();
m.max(a,b);
}
}
class Maxnum
{
int max()
{
int x=10,y=13;
if(x>y)
{
return x;
}
else
{
return y;
}
}
}
class Main
{
public static void main(String args[])
{
Maxnum m=new Maxnum();
int p=m.max();
System.out.println(p);
}
}
import java.util.*;
class Maxnum
{
int max()
{
int x,y;
Scanner s=new Scanner(System.in);
System.out.println("Enter x ,y values");
x=s.nextInt();
y=s.nextInt();
if(x>y)
{
return x;
}
else
{
return y;
}
}
}
class Main
{
public static void main(String args[])
{
Maxnum m=new Maxnum();
int p=m.max();
System.out.println(p);
}
}
class Maxnum
{
int max(int x,int y)
{
if(x>y)
{
return x;
}
else
{
return y;
}
}
}
class Main
{
public static void main(String args[])
{
Maxnum m=new Maxnum();
int p=m.max(10,20);
System.out.println(p);
}
}
import java.util.*;
class Maxnum
{
int max(int x,int y)
{
if(x>y)
{
return x;
}
else
{
return y;
}
}
}
class Main
{
public static void main(String args[])
{
Maxnum m=new Maxnum();
int a,b;
Scanner s=new Scanner(System.in);
System.out.println("Enter a ,b values");
a=s.nextInt();
b=s.nextInt();
int p=m.max(a,b);
System.out.println(p);
}
}
class Maxnum
{
String max()
{
int x=10,y=13;
if(x>y)
{
return "x is max";
}
else
{
return "y is max";
}
}
}
class Main
{
public static void main(String args[])
{
Maxnum m=new Maxnum();
String p=m.max();
System.out.println(p);
}
}
import java.util.*;
class Maxnum
{
String max()
{
int x,y;
Scanner s=new Scanner(System.in);
System.out.println("Enter x ,y values");
x=s.nextInt();
y=s.nextInt();
if(x>y)
{
return "x is max";
}
else
{
return "y is max";
}
}
}
class Main
{
public static void main(String args[])
{
Maxnum m=new Maxnum();
String p=m.max();
System.out.println(p);
}
}
class Maxnum
{
String max(int x,int y)
{
if(x>y)
{
return "x is max";
}
else
{
return "y is max";
}
}
}
class Main
{
public static void main(String args[])
{
Maxnum m=new Maxnum();
String p=m.max(10,20);
System.out.println(p);
}
}
import java.util.*;
class Maxnum
{
String max(int x,int y)
{
if(x>y)
{
return "x is max";
}
else
{
return "y is max";
}
}
}
class Main
{
public static void main(String args[])
{
Maxnum m=new Maxnum();
int a,b;
Scanner s=new Scanner(System.in);
System.out.println("Enter a ,b values");
a=s.nextInt();
b=s.nextInt();
String p=m.max(a,b);
System.out.println(p);
}
}
import java.util.*;
class Factorial
{
void fact()
{
int x,f=1,n;
Scanner s=new Scanner(System.in);
System.out.println("Enter n Value");
n=s.nextInt();
for(x=1;x<=n;x++)
{
f=f*x;
}
System.out.println(f);
}
}
public class Main {
public static void main(String[] args) {
Factorial f=new Factorial();
f.fact();
}
}
import java.util.*;
class Factorial
{
void fact(int n)
{
int x,f=1;
for(x=1;x<=n;x++)
{
f=f*x;
}
System.out.println(f);
}
}
public class Main {
public static void main(String[] args) {
Factorial f=new Factorial();
int n;
Scanner s=new Scanner(System.in);
System.out.println("Enter n Value");
n=s.nextInt();
f.fact(n);
}
}
import java.util.*;
class Factorial
{
int fact()
{
int x,f=1,n;
Scanner s=new Scanner(System.in);
System.out.println("Enter n Value");
n=s.nextInt();
for(x=1;x<=n;x++)
{
f=f*x;
}
return f;
}
}
public class Main {
public static void main(String[] args) {
Factorial f=new Factorial();
int a=f.fact();
System.out.print(a);
}
}
import java.util.*;
class Factorial
{
int fact(int n)
{
int x,f=1;
for(x=1;x<=n;x++)
{
f=f*x;
}
return f;
}
}
public class Main {
public static void main(String[] args) {
Factorial f=new Factorial();
int n;
Scanner s=new Scanner(System.in);
System.out.println("Enter n Value");
n=s.nextInt();
int a=f.fact(n);
System.out.print(a);
}
}