Reset
Constructor Over Loading
Program Info
Program Code
×

Constructor Over Loading

There is Constructor Over Loading.

Footer

×

Constructor Over Loading

class Car{
        int price; // 0
        String name; // null
        Car(){ // default constructor

        }

        Car(int p, String s){ // Parameter constructor
            price = p;
            name = s;
        }

        Car(String s, int x){
            price = x;
            name = s;
        }

        void print(){
            System.out.println(price+" "+name);
        }
        
    }

public class Constructor_Over_Loading_In_OOP {

    public static void main(String[] args) {
        Car c1 = new Car(1250000,"Kia Sonet");
        Car c2 = new Car("Lord Alto",400000);
        Car c3 = new Car();
        c3.price = 123000;
        c3.name = "Honda Amaze";
        c1.print();
        c2.print();
        c3.print();

    }
   
}

Footer

Inherit Parent Class To Child Class
Program Info
Program Code
×

Inherit Parent Class To Child Class

We are inheriting parent class to child class.

Footer

×

Inherit Parent Class To Child Class

// Parent class
class Animal {
    void eat() {
        System.out.println("This animal eats food");
    }
}

// Child class
class Dog extends Animal {
    void bark() {
        System.out.println("Dog is barking");
    }
}

// Main class
public class Inherit_Parent_Class_To_Child_Class_In_OOP {
    public static void main(String[] args) {
        Dog d = new Dog();

        d.eat();   // inherited method
        d.bark();  // own method
    }
}

Footer

Member Of Class With Static Keyword
Program Info
Program Code
×

Member Of Class With Static Keyword

There are some Member Of Class With Static Keyword.

Footer

×

Member Of Class With Static Keyword


class Cricketer{
    static String country = "NZ";
    int runs;
    String name;
    double avg;
    void print(){
        System.out.println(runs+" "+name+" "+avg);
    }
    
}

public class Member_Of_Class_With_Static_Keyword_In_OOP {

    public static void main(String[] args) {
       Cricketer c1 = new Cricketer();
       Cricketer c2 = new Cricketer();
       c1.country = "India";
       System.out.println(c2.country);

    }
   
}

Footer

Pass Array To Constructor
Program Info
Program Code
×

Pass Array To Constructor

We are passing array to constructor.

Footer

×

Pass Array To Constructor

import java.util.Arrays;

class StudentData{
        String name;
        int rno;
        int[] marks;
        StudentData(int[] s){
            marks = Arrays.copyOf(s,s.length);
        }
        StudentData(int s){
            marks = new int[s];
        }
}

public class Pass_Array_To_Constructor_In_OOP {

    public static void main(String[] args) {
        int[] arr = {4,7,1,4,8};
        StudentData s1 = new StudentData(arr);
        s1.marks[0] = 40;
        System.out.println(arr[0]);
        System.out.println(s1.marks[0]);
        StudentData s2 = new StudentData(2);

    }
   
}

Footer

PolyMorphism Concept
Program Info
Program Code
×

PolyMorphism Concept

There is PolyMorphism Concept.

Footer

×

PolyMorphism Concept


public class PolyMorphism_Concept_In_OOP {

    public static class Dog{
        void speak(){
            System.out.println("Bhau Bhau");
        }
    }
    public static class Cat{
        void speak(){
            System.out.println("Meow Meow");
        }
    }
    public static class Lion{
        void speak(){
            System.out.println("GRRRRRR");
        }
    }
    public static class Pikachu{
        void speak(){
            System.out.println("Pika Pika");
        }
    }
    public static class Human{
        void speak(){
            System.out.println("Hello");
        }
    }

    public static void main(String[] args) {
        Dog tommy = new Dog();
        Cat c = new Cat();
        Human bishal = new Human();
        Pikachu p = new Pikachu();

        tommy.speak();
        c.speak();
        p.speak();
        bishal.speak();

    }
   
}

Footer

Showing page  1  of  2  (Total  6 records)
12 Next »
×
Name : Krishna Verma    |    Father's Name : Mr. Satish Kumar    |    Email ID : krishnaverma28081997@gmail.com    |    Religion : Hindu    |    Address : Dayampur, kanker khera, Meerut Cantt (250001), UP    |    Date of Birth : 28 August 1997    |    Marital Status : Non-Married    |    Place of Birth : Dayampur Kanker Khera Meerut Cantt.    |    Gender : Male    |    Age : 28    |    Contact : 9520335394    |    Father's Occupation : Sports man    |    Mother's Name : Smt. Kuntesh Devi    |    Mother's Occupation : Homemaker    |    Number of Brothers : 1    |    Number of Sisters : 1    |    Current Residence : Dayampur kanker khera meerut cantt    |    Family Type : Nuclear Family    |    Family Name : verma    |    Height : 5' 6"    |    Weight : 70 kg    |    Complexion : Fair    |    Body Type : Athletic    |    Hair Color : Black    |    Health Status : Good    |    Any Physical Disability : No    |    Highest Qualification : B.Tech (CSE)    |    Master Skill : PHP Laravel    |    Total Projects : 40 +    |    Total Skills : 25 +    |    Languages Known : Hindi and English    |    Website : krishnaportfolio.in    |    Siblings : 3    |    Nationality : Indian    |    Total Experience : 5 Years    |    LinkedIn : https://www.linkedin.com/in/krishna-verma-840b71356/    |    Total Programs : 10000    |    Total Projects : 40    |    Total Skills : 25    |    Total Experience : 5    |    Total DSA Problems : 165    |    Total Served Companies : 2