LEC : 19 || JAVA

         

LEC:19

Constructors and Their Types in JAVA





Source Code:

package oops;

import java.util.Scanner;

class Student{
    private 
    int i;
//    void display()
//    {
//        System.out.println("Hello new Class and their Objects...");
//    }
//    int get()
//    { int a=99;
//        return a;
//    }
    
    
    //Constructor 
    Student()
    {
        i=99;
        System.out.println("Default Constructor is Calling "+i);
    }
    Student(int a)
    {
        i=a;
        System.out.println("Parameterized  Constructor is Calling "+i);
    }
}

public class OOPS {
    public static void main(String[] args) {
        //Object creation  and calling method  also passing the values 
        Student O1=new Student();
        
        Scanner O4=new Scanner(System.in);
        int input=O4.nextInt();
        Student O2=new Student(input);
//        O1.display();
//        int hold=O1.get();
//        System.out.println("The value of a is : "+hold);


      }
    
}


Comments

Popular posts from this blog

RunwayWithCode

web development Lectures

C++ Lectures