Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week 2 #4

Open
wants to merge 7 commits into
base: MAIN
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions QUESTION 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This is the outer class named School
class School {
// This is the inner class named Student
class Student {
// This is a method in inner class Student
public void print() {
System.out.println("Hi! I am inner class STUDENT of outer class SCHOOL.");

}
}
}

public class Question211{
public static void main(String[] args) {
// Create an object of inner class Student
School.Student s1= new School().new Student();
// Access the 'print()' method of the inner class Student using the inner class object
s1.print();
}
}
28 changes: 28 additions & 0 deletions QUESTION 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This is the class named School
class School {
// This is a method in class School
public void print() {
System.out.println("Hi! I class SCHOOL.");
}
}
// This is the class named Student
class Student {
// This is a method in class Student
public void print() {
System.out.println("Hi! I am class STUDENT");
}
}

public class Question212{
public static void main(String[] args) {
// Create an object of class Student
Student stu = new Student();
// Call 'print()' method of class Student
stu.print();
// Create an object of class School
School sch = new School();
// Call 'print()' method of class School
sch.print();

}
}
20 changes: 20 additions & 0 deletions QUESTION 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This is the main class Question
public class Question213{
public static void main(String[] args) {
// Object of the main class is created
Question213 q = new Question213();
// Print method on object of Question class is called
q.studentMethod();
}

// 'print()' method is defined in class Question
void print(Question213 object){
System.out.print("Well Done!");
}
// Define a method named 'studentMethod()' in class Question
void studentMethod(){
// Call the method named 'print()' in class Question
Question213 q = new Question213();
q.print(q);
}
}
15 changes: 15 additions & 0 deletions QUESTION 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This is the main class Question
public class Question214{
public static void main(String[] args){
Answer a = new Answer(10,"MCQ");
}
}
class Answer{
Answer(){
System.out.println("You got nothing.");
}
Answer(int marks, String type){
this();
System.out.println("You got "+marks+" for an "+ type);
}
}
11 changes: 11 additions & 0 deletions QUESTION 5
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Question215{
public static void main(String[] args) {
//Declare variable with name 'nptel', 'space' and 'java' and proper datatype.
String nptel,space,java;
//Initialize the variables with proper input
nptel="NPTEL";
space=" ";
java="JAVA";
System.out.print(nptel+space+java);
}
}
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# SWAYAM-Programming_In_Java-NPTEL
# SWAYAM-Programming_In_Java-NPTEL
# WEEK 2
Java Week 2:Q1 To call the method print() in class Student following the concept of inner class.

Java Week 2:Q2 To call the method print() of class Student first and then call print() method of class School.

Java Week 2:Q3 To call print() method of class Question by creating a method named ‘studentMethod()’.

Java Week 2:Q4 To call default constructor first and then any other constructor in the class Answer.

Java Week 2:Q5 To debug the program which is intended to print 'NPTEL JAVA'.
156 changes: 0 additions & 156 deletions WEEK-1/QUESTION 1

This file was deleted.

1 change: 0 additions & 1 deletion WEEK-1/QUESTION 2

This file was deleted.

1 change: 0 additions & 1 deletion WEEK-1/QUESTION 3

This file was deleted.

1 change: 0 additions & 1 deletion WEEK-1/QUESTION 4

This file was deleted.

1 change: 0 additions & 1 deletion WEEK-1/QUESTION 5

This file was deleted.