Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

OOP Using Java Assignment 1 CMPLT

best OOP with java

Uploaded by

Mark
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

OOP Using Java Assignment 1 CMPLT

best OOP with java

Uploaded by

Mark
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

NAME-RISHIRAJ PARMAR

Assignment 1

Object Oriented Programming using Java

Q No Question

1 Write a program to find the sum of all integers greater than 40 and less than 250
that are divisible by 5.

2 Create a Java program demonstrating class implementation. Define a class with


data members, such as Student Name, SAP Id, and Marks, along with methods
named setData(String name, int id, double marks) and getData() to manage
customer information. Invoke these methods within the main method to showcase
the functionality of the class.

3 Explain polymorphism in Java and provide a suitable program demonstrating


compile-time polymorphism.

ANSWER 1.

class abc

public static void main(String arg[]){

int sum=0;

for(int i=40;i<251;i++){

if(i%5==0 ){

System.out.println(i);

sum=sum+i;

}
System.out.println("the sum of intergers from 40 to 250 that are divisible
by 5 \n" + sum);

ANSWER 2.

public class Student {

private String name;

private int id;

private double marks;

public void setData(String name, int id, double marks) {

this.name = name;

this.id = id;

this.marks = marks;

public String getData() {

return "Student Name: " + name + "\nSAP Id: " + id + "\nMarks: " +
marks;

public static void main(String[] args) {

Student student = new Student();


student.setData("John Doe", 123456789, 90.0);

System.out.println(student.getData());

ANSWER 3.

Compile Time Polymorphism in Java?

Early binding or static polymorphism are other names for compile time
polymorphism in Java. Compile time polymorphism gets its name from the fact
that the binding is done at the time of compilation. Connecting the function call
and the function body is referred to as binding. It is accomplished via
overloading operators and methods as well as by modifying the function’s
signature. The class’s reference variable handles the overloading of methods.
By adding additional features to an operator, operator overloading is
accomplished. The return value and its type, as well as the parameters and their
types, are referred to as the function’s signature. It outlines a function’s input
and output.

Example of Compile Time Polymorphism in Java:

class SimpleCalculator

int add(int a, int b)

return a+b;

}
int add(int a, int b, int c)

return a+b+c;

public class DemoCal

public static void main(String args[])

SimpleCalculator obj = new SimpleCalculator();

System.out.println(obj.add(10, 20));

System.out.println(obj.add(10, 20, 30));

You might also like