Merging Result
Merging Result
import java.io.*;
class Geek
{
int num;
String name;
Geek()
{
System.out.println("Constructor called");
}
}
class GFG
{
public static void main (String[] args)
{
Geek geek1 = new Geek();
System.out.println(geek1.name);
System.out.println(geek1.num);
}
}
output
Constructor called
null
0
*** ENCAPSULATION ***
class Encapsulate {
private String geekName;
private int geekRoll;
private int geekAge;
public int getAge() { return geekAge; }
output
return i;
}
try
{
res = divideByZero(a,b);
}
catch(NumberFormatException ex)
{
System.out.println("NumberFormatException is occured");
}
return res;
}
int a = 1;
int b = 0;
try
{
int i = computeDivision(a,b);
}
catch(ArithmeticException ex)
{
System.out.println(ex.getMessage());
}
}
}
output
/ by zero
***INHERITANCE IN JAVA***
class Bicycle{
public int gear;
public int speed;
public Bicycle(int gear, int speed)
{
this.gear = gear;
this.speed = speed;
}
public void applyBrake(int decrement)
{
speed -= decrement;
}
output
Geek
10
***CONSTRUCTOR IN JAVA***
abstract class Shape {
String color;
abstract double area();
public abstract String toString();
public Shape(String color)
{
System.out.println("Shape constructor called");
this.color = color;
}
public String getColor() { return color; }
}
class Circle extends Shape {
double radius;
double length;
double width;
System.out.println(s1.toString());
System.out.println(s2.toString());
}
}
OUTPUT
30
60
31.0
***OVERRIDING IN JAVA***
class Parent {
void show()
{
System.out.println("Parent's show()");
}
}
class Child extends Parent {
@Override
void show()
{
System.out.println("Child's show()");
}
}
class Main {
public static void main(String[] args)
{
Parent obj1 = new Parent();
obj1.show();
Parent obj2 = new Child();
obj2.show();
}
}
output
Parent's show()
Child's show()
***POLYORPHISM IN JAVA***
class Helper {
static int Multiply(int a, int b)
{
return a * b;
}
static double Multiply(double a, double b)
{
return a * b;
}
}
class GFG {
public static void main(String[] args)
{
System.out.println(Helper.Multiply(2, 4));
System.out.println(Helper.Multiply(5.5, 6.3));
}
}
output
8
34.65