0% found this document useful (0 votes)
2 views2 pages

Java Oop 10 Mark Answers With Code

The document contains Java code examples demonstrating object-oriented programming concepts. It includes a class for student details using reference variables, a demonstration of inheritance and method overriding with a Person and Student class, and a program to calculate the factorial of a number using command line arguments. Each example is structured with a main method to execute the code.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Java Oop 10 Mark Answers With Code

The document contains Java code examples demonstrating object-oriented programming concepts. It includes a class for student details using reference variables, a demonstration of inheritance and method overriding with a Person and Student class, and a program to calculate the factorial of a number using command line arguments. Each example is structured with a main method to execute the code.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JAVA OBJECT ORIENTED PROGRAMMING – 10

MARK ANSWERS (WITH CODE)

1. Student Details using Reference Variables


class Student {
int rollNo;
String name, branch, mobile, address;
}

public class Main {


public static void main(String[] args) {
Student S1 = new Student();
Student S2 = new Student();

[Link] = 101;
[Link] = "Rahul";
[Link] = "CSE";
[Link] = "9876543210";
[Link] = "Bangalore";

[Link] = 102;
[Link] = "Anita";
[Link] = "ECE";
[Link] = "9123456789";
[Link] = "Mysore";

[Link]([Link] + " " + [Link]);


[Link]([Link] + " " + [Link]);
}
}

2. OOP Principles
class Person {
private String name;
public void setName(String n){ name = n; }
public String getName(){ return name; }
public void role(){ [Link]("Person"); }
}

class Student extends Person {


public void role(){ [Link]("Student"); }
}

public class Main {


public static void main(String[] args) {
Person p = new Student();
[Link]("Amit");
[Link]();
}
}

8. Factorial using Command Line Arguments


public class Main {
public static void main(String[] args) {
int n = [Link](args[0]);
int fact = 1;
for(int i=1;i<=n;i++)
fact *= i;
[Link]("Factorial = " + fact);
}
}

You might also like