+ 1

What's wrong with my code?

import java.util.*; class Student { public int rollno; public String name; Student(int rollno,String name) { this.rollno=rollno; this.name=name; } void output() { System.out.println("Name of student:"+name); System.out.println("Rollno:"+rollno); } } class Student1 extends Student { double height; int weight; Student1(int rollno,String name,double height,int weight) { super(rollno,name); this.height =height; this.weight =weight; } void output() { super.output(); System.out.println("Height:"+height); System.out.println("Weight:"+weight); } public static void main(String args[]) { Scanner obj1=new Scanner(System.in); System.out.println("Enter rollno:"); rollno=obj1.nextInt(); System.out.println("Enter name:"); name=obj1.next(); System.out.println("Enter height:"); height=obj1.nextDouble(); System.out.println("Enter weight:"); weight=obj1.nextInt(); Student1 s1 = new Student1(rollno,name,height,weight); s1.output(); } }

11th Oct 2021, 3:17 PM
maha Lakshmi
maha Lakshmi - avatar
4 odpowiedzi
+ 7
maha Lakshmi , sorry to say, but this code has a poor readability. if you expect people to help, you should put some effort in giving a well formatted source code. this is a link to the guideline for people that are doing code for google: https://google.github.io/styleguide/javaguide.html
11th Oct 2021, 4:35 PM
Lothar
Lothar - avatar
+ 3
because Student1 object doesn't exist, variables in main() are local and undeclared, add this to main() String name; int rollno, weight; double height;
11th Oct 2021, 4:31 PM
zemiak
+ 2
maha Lakshmi You didn't define data type in main method variable. https://code.sololearn.com/c3Of755Jce7s/?ref=app
11th Oct 2021, 4:34 PM
A͢J
A͢J - avatar
11th Oct 2021, 4:37 PM
zemiak