We are doing add two integer numbers and print result.
×
Addition of Two Integer Numbers
public class addition_of_two_int_value
{
public static void main(String[] args)
{
int x = 5;
int y = 6;
System.out.println(x + y); // Print the value of x + y
}
}
We are calling an interface method that does not have an body.
×
Calling Interface Method
interface Animal
{
public void animalSound(); // interface method (does not have a body)
public void sleep(); // interface method (does not have a body)
}
class Pig implements Animal
{
public void animalSound()
{
System.out.println("The pig says: wee wee");
}
public void sleep()
{
System.out.println("Zzz");
}
}
class call_interface_method_which_does_not_have_a_body
{
public static void main(String[] args)
{
Pig myPig = new Pig();
myPig.animalSound();
myPig.sleep();
}
}
We are doing cast an integer data to double and print them.
×
Casting Integer Data to Double
public class Automatic_casting_int_to_double
{
public static void main(String[] args)
{
int myInt = 9;
double myDouble = myInt; // Automatic casting: int to double
System.out.println(myInt);
System.out.println(myDouble);
}
}
We are doing modify value through call a method of class.
×
Modify Value Through Call a Method of Class
class A
{
int x;
void f1()
{
int y=5;
x=y;
}
}
class call_f1_method_through_object_of_class_A_and_print_some_value_of_object2
{
public static void main(String[] aa)
{
A a=new A();
a.f1();
System.out.println(a.x);
}
}
We are doing print sum of numbers though call a method.
×
Print Sum of Numbers Though Call Method
public class before_call_and_print_myMethod_parameterised_function_using_return
{
static int myMethod(int x, int y)
{
return x + y;
}
public static void main(String[] args)
{
int z = myMethod(5, 3);
System.out.println(z);
}
}